Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 28th, 2007, 02:29 PM
Registered User
 
Join Date: Feb 2007
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.

 
Old March 18th, 2007, 03:42 AM
Registered User
 
Join Date: Mar 2007
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






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





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