This is the code: function setWatermark($WaterMark, $SourceFile, $DestinationFile){ $photo = imagecreatefromjpeg($SourceFile); $watermark = imagecreatefrompng($WaterMark); imagealphablending($photo, true); $offset = 10; imagecopy($photo, $watermark, imagesx($photo) - imagesx($watermark) - $offset, $offset, 0, 0, imagesx($watermark), imagesy($watermark)); if ($DestinationFile<>'') { imagejpeg ($photo, $DestinationFile, 100); } else { // Output to the browser header('Content-Type: image/jpeg'); imagejpeg($photo, null, 100); }; imagedestroy($photo); } PHP: *this puts the watermark in the top right corner of the image. The problem is when I add this watermark to a small image (300 x 360) it takes a big part of the image. How can I resize the watermark without saving it (replacing the original)? Or maybe you have other idea that solves this problem? thanks
You can read the dimension of your photo with the function imagesx and imagesy. Then depending on the size of that image you can resize your watermark in php and add it to your photo like you do already do. For some resizing examples check the PHP Doc for the function imagecopyresampled -> Link
It works great but I'm using *.png watermark and when I'm using imagecopyresampled I get black background. How can I fix it? (the actual background is empty transparent)
You can try to use the imagecopyresized function instead or try the following to preserve transperancy with imagecopyresampled (not tested, just found that on the php site in a comment). Add this before the imagecopyresampled: imagealphablending($watermark, false); $color = imagecolortransparent($watermark, imagecolorallocatealpha($watermark, 0, 0, 0, 127)); imagefill($watermark, 0, 0, $color); imagesavealpha($watermark, true); PHP: