View Full Version : image resize and watermark / 2 scripts in one

09-09-2009, 08:58 PM
Hello everyone,

I need a little help. I'm not a PHP expert, I think this one is an easy one but still... I cannot solve it :P

I have 2 scripts, one for Image resizing and another one for watermark. I need to merge these 2 scripts in one. First to do the image resizing and then apply the watermark, and post the resulted image. I don/t know why it doesnt work to use for the watermark script the result of the first script....

I will attach the two scripts. Thanks a lot for you help.


09-09-2009, 09:23 PM
this should work, but i haven't tested it;

header('content-type: image/jpeg');
$img = $_GET['img'];
$watermark = imagecreatefrompng('watermark.png');

$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = imagecreatefromjpeg("$img");
$size = getimagesize("$img");
$dest_x = $size[0]/2 - $watermark_width/2 ;
$dest_y = $size[1]/2 - $watermark_height/2;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);

imagecopyresized($image, $watermark, 0, 0, 0, 0, imagesx($image), imagesy($image), $size[0], $size[1]);


09-10-2009, 08:14 PM
thanks angst,

In your code I cannot figure how I can send the size of the resized image that I want. Anyway, I figured myself how to merge the two scripts and it-s solved now by adding the watermark script inside the resizing script and the right variable to use was $src

$img = $_GET['img']; / $img = $src;

Thanks for your time.