PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sun Aug 09, 2020 6:30 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: Building an Image
PostPosted: Fri Sep 09, 2005 7:09 pm 
Offline
Forum Contributor
User avatar

Joined: Sat Jan 03, 2004 5:55 pm
Posts: 202
Location: Cleveland, OH


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 7:11 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 7:16 pm 
Offline
Forum Contributor
User avatar

Joined: Sat Jan 03, 2004 5:55 pm
Posts: 202
Location: Cleveland, OH
I originally didn't have that, but I read somewhere that I was supposed to... I removed it with no change.

Syntax: [ Download ] [ Hide ]
<?

require_once("include/layout/header.php");

Header("Content-Type: image/png");



Captcha("Test"); ?>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 7:20 pm 
Offline
Forum Commoner

Joined: Tue Jun 14, 2005 2:55 pm
Posts: 46
Leave out the
Syntax: [ Download ] [ Hide ]
require_once("include/layout/header.php");
(I'm assuming that has normal HTML or PHP output in it), and it should work fine.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 7:31 pm 
Offline
Forum Contributor
User avatar

Joined: Sat Jan 03, 2004 5:55 pm
Posts: 202
Location: Cleveland, OH
Well, Closer I think. I still get no output... So I've simplified. Rather than using a function to build, I just consolidated it into a single file.

Syntax: [ Download ] [ Hide ]
<?

Header("Content-Type: image/png");



// Create The Image WxH

$myimage = ImageCreate(200, 40);



// Fill Image Black

ImageFill($myimage, 0, 0, $black);



// Write Message

ImageString($myimage, 4, 96, 19, "Test", $white);



// Output Image

ImagePNG($myimage);



?>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 7:41 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
try accessing that script directly..

make sure there are no additional characters outside of php's processing..


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 7:46 pm 
Offline
Forum Contributor
User avatar

Joined: Sat Jan 03, 2004 5:55 pm
Posts: 202
Location: Cleveland, OH
One step ahead of you... I am accessing the file, and I'm getting nothing. Also, accessing from an img tag on the other page doesn't even give a broken image.

Sorry to be such a pain :( I thought this would be the easy part of the experiment lol.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 7:50 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
have you checked your error logs?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 7:52 pm 
Offline
Forum Commoner

Joined: Tue Jun 14, 2005 2:55 pm
Posts: 46
Hmmm... are you sure there are no newlines, spaces, anything like that outside the <? ... ?> tags?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 8:01 pm 
Offline
Forum Contributor
User avatar

Joined: Sat Jan 03, 2004 5:55 pm
Posts: 202
Location: Cleveland, OH
HAHAHA Good Call Feyd....

Syntax: [ Download ] [ Hide ]
[Fri Sep  9 19:49:23 2005] [error] PHP Fatal error:  imagepng() [<a href='function.imagepng'>function.imagepng</a>]: gd-png:  fatal libpng error: Invalid number of colors in palette\n in /home/zoneprof/public_html/verify.php on line 13

[Fri Sep  9 19:45:20 2005] [error] PHP Fatal error:  imagepng() [<a href='function.imagepng'>function.imagepng</a>]: gd-png:  fatal libpng error: Invalid number of colors in palette\n in /home/zoneprof/public_html/verify.php on line 13

[Fri Sep  9 19:44:17 2005] [error] PHP Fatal error:  imagepng() [<a href='function.imagepng'>function.imagepng</a>]: gd-png:  fatal libpng error: Invalid number of colors in palette\n in /home/zoneprof/public_html/verify.php on line 15

[Fri Sep  9 19:43:54 2005] [error] PHP Fatal error:  imagepng() [<a href='function.imagepng'>function.imagepng</a>]: gd-png:  fatal libpng error: Invalid number of colors in palette\n in /home/zoneprof/public_html/verify.php on line 15

[Fri Sep  9 19:39:51 2005] [error] PHP Fatal error:  imagepng() [<a href='function.imagepng'>function.imagepng</a>]: gd-png:  fatal libpng error: Invalid number of colors in palette\n in /home/zoneprof/public_html/verify.php on line 14

code]



About 400 times.



I tried adding...
Syntax: [ Download ] [ Hide ]
ImageTrueColorToPalette( $myimage, false, 256 );


To Move to palette color, but still giving the error.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 8:03 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
try using imagejpeg(), or imagecreatetruecolor() or both.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 8:03 pm 
Offline
Forum Commoner

Joined: Tue Jun 14, 2005 2:55 pm
Posts: 46
Well, I've tried it myself, and after a bit of fiddling, all I can come up with is to try changing the header to gif and the output to ImageGIF. That works for me.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 8:15 pm 
Offline
Forum Commoner

Joined: Tue Jun 14, 2005 2:55 pm
Posts: 46
Done it!

For some reason with PNGs, you need to use ImageColorAllocate() to make things change colour. So...

Syntax: [ Download ] [ Hide ]
<?php



Header ("Content-type: image/png");

$myimage = ImageCreate (200, 40);

$bgcolor = ImageColorAllocate ($myimage, 0, 0, 0);

$textcolor = ImageColorAllocate ($myimage, 255, 255, 255);

ImageString ($myimage, 4, 96, 19,  "test", $textcolor);

ImagePng ($myimage);



?>


You should probably look into this on php.net to find out more about it why you had a problem.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 8:36 pm 
Offline
Forum Contributor
User avatar

Joined: Sat Jan 03, 2004 5:55 pm
Posts: 202
Location: Cleveland, OH


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 10, 2005 11:29 am 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com
http://www.ooer.com/index.php?section=php&id=9

Might help ..


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group