Jump to content

Watermarking with GD


graham23s

Recommended Posts

Hi Guys,

 

i'm trying to watermark my images with text i have this:

 

<?php
function resize_image($upload_directory, $new_image_name)
{
  // original image location //
  $original_image = $upload_directory;
  
  // set up a canvas sizes //
  $canvas_width = 65;
  $canvas_height = 65;
  
  // create the canvas //
  $canvas = imagecreatetruecolor($canvas_width, $canvas_height);
  
  // make the background color white //
  $white_background = imagecolorallocate($canvas, 255, 255, 255);
  
  // change the background to white //
  imagefill($canvas, 0, 0, $white_background);
  
  // get the image height and width //
  list($image_width, $image_height) = getimagesize($upload_directory);
  
  #########################################
  // RATIO CALCULATIONS //
  $ratio = $image_width / $image_height;
  
    if ($ratio > 1 )
    {
  
  	$new_image_width = 65;
	$new_image_height = 65 / $ratio;
  
     } else {
   
   	$new_image_width = (float) 65 * $ratio;
	$new_image_height = 65;
   
  }
  // RATIO CALCULATIONS //
  #########################################
  
  // store original into memory //
  $original_image = imagecreatefromjpeg($original_image);
  
  // ========================================= //
  // WATERMARK CODE!
  // ========================================= //
  $textcolor = imagecolorallocate($im, 0, 0, 255);

  // write the string at the top left
  imagestring($original_image, 5, 0, 0, "Hello world!", $textcolor);  
  // ========================================= //
  // WATERMARK CODE!
  // ========================================= //
  
  // copy the original image onto the canvas canvas, original and top/left co-ordinates //
  imagecopyresampled($canvas, $original_image, 0,0,0,0, $new_image_width, $new_image_height, $image_width, $image_height);
  
  // thumbnail name //
  $new_thumbnail_name = "thumb-$new_image_name";
  
  // save the thumbnail in the thumbs folder //
  if(imagejpeg($canvas, "products/thumbnails/$new_thumbnail_name", 100))
  {
   return("$new_thumbnail_name");
  }
  
  // destroy the images in memory //
  imagedestroy($original_image);
  imagedestroy($canvas);  
  
} // end function //
?>

 

i highlighted where i have put the watermarking code but its not doing anything! can anyone see the problem?

 

cheers guys

 

Graham

Link to comment
https://forums.phpfreaks.com/topic/113121-watermarking-with-gd/
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.