View Full Version : text onto jpg error

11-27-2007, 10:48 PM
Hi Guys,

i did some pretty basic testing with GD , this code should overlay a watermark/text on uploaded images but im getting a few errors:

part of the code:

$uploaddirectory = "uploads/".$renamedimage;

// Get identifier for white
$white = imagecolorallocate($uploaddirectory, 255, 255, 255);

// Add text to image
imagestring($uploaddirectory, 3, 5, imagesy($uploaddirectory)-20, 'www.xxx.com', $white);


Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/.castle/graham23s/www.site.com/uploadpic.php on line 78

Warning: imagesy(): supplied argument is not a valid Image resource in /home/.castle/graham23s/www.site.com/uploadpic.php on line 81

Warning: imagestring(): supplied argument is not a valid Image resource in /home/.castle/graham23s/www.site.com/uploadpic.php on line 81

not sure what to make of the errors exactly, does it mean the image isn't getting picked up by the gd functions?

cheers guys


11-28-2007, 12:13 AM
The image resource has to be created with imagecreatetruecolor() (http://php.net/imagecreatetruecolor) before you try to use it.

11-28-2007, 12:28 AM
Hi Mate,

i tried making a function for it:

## watermark function

This passes the $filename of the uploaded file to get the extension


function watermark_image($filename,$uploaddirectory) {

## Using GD
## Find out the files extension
$extension = explode(".", $filename);
$extension = $extension[count($extension)-1];

## Make all filenames lowercase
$extension = strtolower($extension);

## Generate image accordingly
if($extension == "jpg" || $extension == "jpeg" || $extension == "pjpeg") {

$image = imagecreatefromjpeg($uploaddirectory);

} elseif($extension == "png") {

$image = imagecreatefrompng($uploaddirectory);

} elseif($extension == "gif") {

$image = imagecreatefromgif($uploaddirectory);


$white = imagecolorallocate($image, 255, 255, 255);

imagestring($image, 3, 5, imagesy($image)-20, 'www.site.com', $white);

echo $extension;


this all looks ok , but when i test it, it just uploads without any errors (but doesn't overlay the text) so theres no errors to speak of, if i echo out the extension it's fine

can you see any errors at all?

thanks mate


11-28-2007, 05:16 AM
You aren't using any output functions like imagejpeg() (http://php.net/imagejpeg). To find out where you're getting an error turn on error_reporting() (http://php.net/error_reporting) and var_dump() (http://php.net/var_dump) the results of your functions.

11-28-2007, 05:49 PM
Or check your apache/IIS logs to see the errors. You can't see errors in an image, but this doesn't mean there were none.

11-29-2007, 11:59 PM
Hi Guys,

thanks for the help i got it fixed