Page 1 of 1

imagecreate(); [solved]

Posted: Wed Mar 15, 2006 3:53 pm
by anthony88guy
I’m really excited about making images on the fly. From a couple tutorials here is the code I came up with:

Code: Select all

<?php
header("Content-type: image/png");

$image['height'] = 50;
$image['width'] = 200;
$image['bgcolor'] = imagecolorallocate($img, 0, 0, 0);
$image['textcolor'] = imagecolorallocate($img, 204, 204, 204);
$image['textsize'] = 12;
$image['text'] = 'testing';

$img = imagecreate($image['height'], $image['width']);
imagefill($img, 0, 0, $image['bgcolor']);
imagestring($img, $image['textsize'], 5, 5, $image['text'], $image['textcolor']);

imagepng($img);
?>
When I run the script I receive the following error:
The image “URL” cannot be displayed, because it contains errors.
I know I haven’t specified a font, I am wondering if that could be the culprit?

Thanks.

[edit]
Viewing the page in IE, I receive the following error:
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/theelite/public_html/members/includes/image.php</b> on line <b>6</b><br />
<br />
<b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/theelite/public_html/members/includes/image.php</b> on line <b>7</b><br />
‰PNG


IHDR2È

Posted: Wed Mar 15, 2006 3:59 pm
by feyd
ensure that you do not have any character data being output besides the script's image.

Posted: Wed Mar 15, 2006 4:07 pm
by anthony88guy
feyd wrote:ensure that you do not have any character data being output besides the script's image.
Nothing besides the image is being outputted.

Posted: Wed Mar 15, 2006 4:14 pm
by SKDevelopment
imagecolorallocate() should use the valid resource $img. Try this:

Code: Select all

<?php 
header("Content-type: image/png"); 

$image['height'] = 50; 
$image['width'] = 200; 
$img = imagecreate($image['height'], $image['width']); 

$image['bgcolor'] = imagecolorallocate($img, 0, 0, 0); 
$image['textcolor'] = imagecolorallocate($img, 204, 204, 204); 
$image['textsize'] = 12; 
$image['text'] = 'testing'; 


imagefill($img, 0, 0, $image['bgcolor']); 
imagestring($img, $image['textsize'], 5, 5, $image['text'], $image['textcolor']); 

imagepng($img); 
?>
--
Best Regards,
Sergey Korolev
www.SKDevelopment.com

Posted: Wed Mar 15, 2006 4:15 pm
by feyd
well, you have those warnings.. which should lead you somewhere. :P