aainaarz
aainaarz

Reputation: 902

PHP created watermark looks strange

I have script that add water mark (PNG, transparent) to image(JPG). Works fine with a catch - in some way water mark changes colors and makes it NOT transparent. This is code i use for adding water mark:

$im = imagecreatefromjpeg('../../pics/'.$ran.'_large.jpg');
$stamp = imagecreatefrompng('a.png');

$marge_right = 10;
$marge_bottom = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);

imagecopymerge($im, $stamp, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($stamp), imagesy($stamp), 70);

// Save the image to file and free memory
imagejpeg($im, '../../pics/'.$ran.'_large.jpg');
imagedestroy($im);

Image with watermark after PHP generates it (wrong way)

Upvotes: 0

Views: 173

Answers (3)

aainaarz
aainaarz

Reputation: 902

thank you for help guys - I found answer in this site

$im = imagecreatefromjpeg('../../pics/'.$ran.'_large.jpg');
$stamp = imagecreatefrompng('a.png');

imagealphablending($im, true);

$marge_right = 10;
$marge_bottom = 10;

$sx = imagesx($stamp);
$sy = imagesy($stamp);

$offset = 10;

imagecopy($im, $stamp, imagesx($im) - imagesx($stamp) - $offset, imagesy($im) - imagesy($stamp) - $offset, 0, 0, imagesx($stamp), imagesy($stamp));
// Save the image to file and free memory
imagejpeg($im, '../../pics/'.$ran.'_large.jpg');
imagedestroy($im);

Upvotes: 0

Shiplu Mokaddim
Shiplu Mokaddim

Reputation: 57650

Your output image format is jpeg. Jpeg does not support transaprency. Change your output format to png.

Also suggest you to use image magic. Gd is very primitive.

Upvotes: 1

kingmaple
kingmaple

Reputation: 4310

Don't forget these functions when it comes to PNG images with alpha maps after creating it from PNG:

imagealphablending($stamp,false);
imagesavealpha($stamp,true);

See if it makes any difference?

Upvotes: 0

Related Questions