...

View Full Version : text onto jpg error



graham23s
11-27-2007, 09: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:


<?php
$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);
?>

errors:


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

Graham

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

graham23s
11-27-2007, 11:28 PM
Hi Mate,

i tried making a function for it:


<?php
## watermark function
watermark_image($filename,$uploaddirectory);
?>

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

function:


<?php
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

Graham

Inigoesdr
11-28-2007, 04: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.

aedrin
11-28-2007, 04: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.

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

thanks for the help i got it fixed

Graham



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum