【问题标题】:Watermarking centered instead of top right水印居中而不是右上角
【发布时间】: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


    【解决方案1】:

    像这样更新坐标变量

    $coordinateX = ($imageWidth - $watermarkWidth) / 2;
    $coordinateY = ($imageHeight - $watermarkHeight) / 2;
    

    【讨论】:

    • 谢谢!祝你有美好的一天。
    猜你喜欢
    • 1970-01-01
    • 2020-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-18
    相关资源
    最近更新 更多