Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 28th, 2007, 02:29 PM
Registered User
 
Join Date: Feb 2007
Location: Reedley, CA, USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default imagepng(); Error

I have the following code:

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Test Site</title>
</head>
<body>
<?php
    $MyImage = imagecreate(200,100);
    $MyGrey = imagecolorallocate($MyImage,204,204,204);
    $MyBlack = imagecolorallocate($MyImage,0,0,0);
    imageline($MyImage, 15, 35, 120, 60, $MyBlack);
    header("content-type: image/png");
    imagepng($MyImage);
    imagedestroy($MyImage);
?>

<p>&nbsp;</p>
<p>Test Page
</p>
</body>
</html>
---------------

When I run this, I get the following:

‰PNG  IHDRÈdùHíHPLTEÌÌÌÓ33dMIDATxœc`£` Àx§” Nf*k²Ã)Ãø§”•5}À)ŏS†ÚšpJUà a§²¦œ2ÔŽw<špJ‚Q0 †; u%ÍæËIEND®B`‚


Test Page
--------------

Why is it not displaying the image instead of the code?

PHP v. 5.1.4
in phpinfo();

GD Support enabled
GD Version bundled (2.0.28 compatible)
FreeType Support enabled
FreeType Linkage with freetype
FreeType Version 2.1.9
T1Lib Support enabled
GIF Read Support enabled
GIF Create Support enabled
JPG Support enabled
PNG Support enabled
WBMP Support enabled
XBM Support enabled

Thank you.

Reply With Quote
  #2 (permalink)  
Old March 18th, 2007, 03:42 AM
Registered User
 
Join Date: Mar 2007
Location: , , Afghanistan.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Rhymhoont,

Try to create a seperate file for your image creation:

image.php
---------
<?php
    $MyImage = imagecreate(200,100);
    $MyGrey = imagecolorallocate($MyImage,204,204,204);
    $MyBlack = imagecolorallocate($MyImage,0,0,0);
    imageline($MyImage, 15, 35, 120, 60, $MyBlack);
    header("content-type: image/png");
    imagepng($MyImage);
    imagedestroy($MyImage);
?>

index.php
---------
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Test Site</title>
</head>
<body>
<?php
include('image.php');
?>

<p>&nbsp;</p>
<p>Test Page
</p>
</body>
</html>

When I look at the code of your image-creation I note that the header (header("content-type: image/png"); ) doesn't correspond with the header of your file (<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">). Perhaps this will solve your problem?

Ciao MvO

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Query Error & Run-Time Error 3022 DavidWE Access 1 July 31st, 2008 11:17 AM
Ch 4: Parse error: syntax error, unexpected T_SL hanizar77 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 0 June 23rd, 2008 09:17 PM
[Resolved] Error calling a sp - parameter error snufse .NET Framework 2.0 2 February 12th, 2008 04:46 PM
Parse error: syntax error, unexpected T_STRING ginost7 Beginning PHP 1 November 9th, 2007 02:51 AM
imagepng(): Unable to open error ss2003 Beginning PHP 3 April 8th, 2004 07:24 PM



All times are GMT -4. The time now is 01:49 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.