Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
evo watermarked
header('content-type: image/jpeg');
// Should be a safe image repository if you
// need to make sense.
$dirprefix = "";
$watermark = $dirprefix."/assets/images/watermark.png";
$image = $dirprefix.$_REQUEST['src'];
watermark($image, $watermark, 2,1);
// The minimumfactors tell how big the image must compared to the watermark
// before the watermark is applied. 2,2 means the image must be at least be 4
// times as big as the watermark.
function watermark($srcfilename, $watermark, $minumfactorx, $minumfactory) {
$imageInfo = getimagesize($srcfilename);
$width = $imageInfo[0];
$height = $imageInfo[1];
$logoinfo = getimagesize($watermark);
$logowidth = $logoinfo[0];
$logoheight = $logoinfo[1];
$horizmargin = $width-$logowidth;
$vertmargin = $height-$logoheight;
$photoImage = ImageCreateFromJPEG($srcfilename);
if ($width>=($logowidth*$minumfactorx) && $height>=($logoheight*$minumfactory)) {
// Only add watermark if watermark fits
ImageAlphaBlending($photoImage, true);
$logoImage = ImageCreateFromPNG($watermark);
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
ImageCopy($photoImage, $logoImage, $horizmargin, $vertmargin, 0, 0, $logoW, $logoH);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment