【发布时间】:2015-05-07 22:07:26
【问题描述】:
我正在使用 php 函数在图像的右上角创建水印。
代码如下:
<?php
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 - 15) - ($watermarkWidth);
$coordinateY = ($imageHeight - 15) - ($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);
if (!($save)) {
exit;
}
}
?>
这个函数在右上角添加了一个水印,但我想把它放在图像的中心。
怎么做?
谢谢
【问题讨论】:
标签: php image-processing gd watermark