Forum Moderators: coopster

Message Too Old, No Replies

php to watermark image

         

icemancast

1:58 pm on Oct 22, 2007 (gmt 0)

10+ Year Member



I have pieced this function together from several tutorials. it is suppose to allow me to upload a jpeg and overlay a png file as a watermark. for some reason i got it to work once and when i rewrote it, it doesn't work. any ideas?

function watermark($source, $copypath, $heightmax){

//header('content-type: image/jpeg');

$jpeg_size = getimagesize($source);
$jpeg_width = $jpeg_size[0];
$jpeg_height = $jpeg_size[1];

// CREATE AN IMAGE FROM THE UPLOAD
$jpeg_image = imagecreatefromjpeg($source);
// TURN BLENDING ON
imagealphablending($jpeg_image, true);

$new_jpeg_height = $heightmax;
// GET MULTIPLIER AND SIZE UP WIDTH TO IT
$new_jpeg_width = round(($new_jpeg_height / $jpeg_height) * $jpeg_width);

// CREATE NEW IMAGE
$new_jpeg_image = imagecreatetruecolor($new_jpeg_width, $new_jpeg_height);
imagecopyresized($new_jpeg_image, $jpeg_image, 0, 0, 0, 0, $new_jpeg_width, $new_jpeg_height, $jpeg_width, $jpeg_height);

//$watermark_logo = '/usr/home/icema/public_html/admin/images/watermark.png';
$watermark_size = getimagesize('watermark.png');
$watermark_width = $watermark_size[0];
$watermark_height = $watermark_size[1];

// CREATE WATERMARK IMAGE
$watermark = imagecreatefrompng('watermark.png');
//$image = imagecreatetruecolor($watermark_width, $watermark_height);

imagecopymerge($new_jpeg_image, $watermark, $new_jpeg_width, $new_jpeg_height, 0, 0, $watermark_width, $watermark_height, 100);

//imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);

// COPY CREATE COPY TO PATH
imagejpeg($new_jpeg_image, $copypath);

// DESTROY TEMPORARY IMAGES
imagedestroy($jpeg_image);
imagedestroy($new_jpeg_image);
imagedestroy($watermark);

//return $copypath;

}

eelixduppy

8:55 pm on Oct 22, 2007 (gmt 0)



Let's start by finding out what exactly isn't working, if you are getting any error messages, and what you changed to make it so that it doesn't work. That should give us a good starting place to help you with your problem.

limoshawn

9:36 pm on Oct 22, 2007 (gmt 0)

10+ Year Member



just a shot in the dark here but should'nt this:

//$watermark_logo = '/usr/home/icema/public_html/admin/images/watermark.png'; 
$watermark_size = getimagesize('watermark.png');

look like this:


$watermark_logo = '/usr/home/icema/public_html/admin/images/watermark.png';
$watermark_size = getimagesize('$watermark_logo');

?

icemancast

11:33 pm on Oct 22, 2007 (gmt 0)

10+ Year Member



where here's what happens it creates the thumbnail first and that happens. it just doesn't overlay the png file and there is no error i get. the comment out was a test i was doing. i commented out because i put the file where the script was.

icemancast

2:09 pm on Oct 24, 2007 (gmt 0)

10+ Year Member



ideas?