I've seen other answers but none address this issue, I have this code
$stamp = imagecreatefrompng('w.png');
$im = imagecreatefromjpeg('image.jpg');
$stw = imagesx($im)/4;
$marge_bottom = 10;
$marge_right = 10;
$sx = imagesx($stamp);
$sy = imagesy($stamp);
imagecopyresized($im, $stamp, $marge_right, $marge_bottom, 0, 0, $stw, $stw, imagesx($stamp), imagesy($stamp));
header("Content-Type: image/jpeg");
imagejpeg($im,NULL,100);
This works but the watermark (stamp) is jagged after being resized
Watermark Should look like this:
Edit:
here is the solution for anyone with this problem, replace the imagecopyresized()
function with imagecopyresampled()
imagecopyresampled($im, $stamp, $marge_right, $marge_bottom, 0, 0, $stw, $stw, imagesx($stamp), imagesy($stamp));
Try imagecopyresampled
instead of imagecopyresized
:
imagecopyresampled($im, $stamp, $marge_right, $marge_bottom, 0, 0, $stw, $stw, imagesx($stamp), imagesy($stamp));
From the manual:
imagecopyresampled() copies a rectangular portion of one image to another image, smoothly interpolating pixel values so that, in particular, reducing the size of an image still retains a great deal of clarity.