1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
| <?
function watermarking($source, $watermark, $save = NULL, $width = null, $height = null) {
$watermark = @imagecreatefrompng($watermark)
or exit("Impossible d'ouvrir le fichier (watermark).");
imageAlphaBlending($watermark, false);
imageSaveAlpha($watermark, true);
$imageString = @file_get_contents($source)
or exit("Impossible d'ouvrir le fichier (image).");
$image = @imagecreatefromstring($imageString)
or exit("Format de fichier (image) inconnu.");
$imageWidth = imageSX($image);
$imageHeight = imageSY($image);
if (!($width)) {
$watermarkWidth = imageSX($watermark);
} else {
$watermarkWidth = $width;
}
if (!($height)) {
$watermarkHeight = imageSY($watermark);
} else {
$watermarkHeight = $height;
}
$coordinateX = ($imageWidth - 5) - ($watermarkWidth);
$coordinateY = ($imageHeight - 5) - ($watermarkHeight);
imagecopy($image, $watermark, $coordinateX, $coordinateY, 0, 0, $watermarkWidth, $watermarkHeight);
if (!($save)) {
header('Content-Type: image/jpeg');
}
imagejpeg ($image, $save, 100);
imagedestroy($image);
imagedestroy($watermark);
}
?> |
Partager