Jump to content

[SOLVED] GD Library & Watermarking?


Solarpitch

Recommended Posts

Hi,

 

I'm currently trying to use the below code to water mark my images been displayed from a database but seem to be getting a load of warnings. Could this be something to do with the GD Library or am I missing something simple?

 

<?php

function watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile) {
   list($width, $height) = getimagesize($SourceFile);
   $image_p = imagecreatetruecolor($width, $height);
   $image = imagecreatefromjpeg($SourceFile);
   imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height);
   $black = imagecolorallocate($image_p, 0, 0, 0);
   $font = 'arial.ttf';
   $font_size = 10;
   imagettftext($image_p, $font_size, 0, 10, 20, $black, $font, $WaterMarkText);
   if ($DestinationFile<>'') {
      imagejpeg ($image_p, $DestinationFile, 100);
   } else {
      header('Content-Type: image/jpeg');
      imagejpeg($image_p, null, 100);
   };
   imagedestroy($image);
   imagedestroy($image_p);
};


		$image = "http://mysite/product_images/floor.jpg;
		$DestinationFile = "http://mysite/watermark.png";
		$WaterMarkText = '';

                        watermarkImage ($SourceFile, $WaterMarkText, $DestinationFile);



?>

 

I basically get all these warnings. The image seems to be fine as does the $image value so not sure why its throwing these errors...

 


Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/f41697/public_html/params/params.php on line 177

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/f41697/public_html/params/params.php on line 179

Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/f41697/public_html/params/params.php on line 180

Warning: imagettftext() expects parameter 1 to be resource, boolean given in /home/f41697/public_html/params/params.php on line 183

Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/f41697/public_html/params/params.php on line 185

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/f41697/public_html/params/params.php on line 190

Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/f41697/public_html/params/params.php on line 191

Link to comment
https://forums.phpfreaks.com/topic/114185-solved-gd-library-watermarking/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.