evo watermarked
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
header('content-type: image/jpeg'); | |
// Should be a safe image repository if you | |
// need to make sense. | |
$dirprefix = "http://sitename.com/"; | |
$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); | |
} | |
ImageJPEG($photoImage); | |
ImageDestroy($photoImage); | |
ImageDestroy($logoImage); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment