Php 水印文本位置右下角

Php 水印文本位置右下角,php,css,watermark,imagettftext,placement,Php,Css,Watermark,Imagettftext,Placement,我使用下面的代码来设置水印,但它将水印设置为中心,我想将其设置为右下角的位置 <?php function watermarkImage($fileget, $watermarktext, $saveto) { list($width, $height) = getimagesize($fileget); $image_p = imagecreatetruecolor($width, $height); $size = getim

我使用下面的代码来设置水印,但它将水印设置为中心,我想将其设置为右下角的位置

<?php
function watermarkImage($fileget, $watermarktext, $saveto) 
    { 
        list($width, $height) = getimagesize($fileget);
        $image_p = imagecreatetruecolor($width, $height);
        $size = getimagesize($fileget);
        $dest_x = $size[0] - $width - 5;  
        $dest_y = $size[1] - $height - 5;
        $image = imagecreatefromjpeg($fileget);
        imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width, $height); 
        $white = imagecolorallocate($image_p, 255, 255, 255);
        $font = FONT_PATH;
        $font_size = 15;
        $bbox = imagettfbbox($font_size, 0, $font, $watermarktext);
        $x = $bbox[0] + (imagesx($image) / 2) - ($bbox[4] / 2) - 25;
        $y = $bbox[1] + (imagesy($image) / 2) - ($bbox[5] / 2) - 5;
        imagettftext($image_p, $font_size, 0, $x, $y, $white, $font, $watermarktext);
        if ($saveto<>'') {
            imagejpeg ($image_p, $saveto, 100); 
        } else {
            header('Content-Type: image/jpeg');
            imagejpeg($image_p, null, 100);
        };
        imagedestroy($image); 
        imagedestroy($image_p); 
    }
?>

我指的是这个答案:


如何将位置设置为右下方向?

不要将
x
y
位置除以
2
。这就是为什么它在中间。在以下方面:

$x = $bbox[0] + (imagesx($image) / 2) - ($bbox[4] / 2) - 25;
$y = $bbox[1] + (imagesy($image) / 2) - ($bbox[5] / 2) - 5;
这应该有效,因为该位置将位于右下角:

$x = $bbox[0] + (imagesx($image)) - ($bbox[4] / 2) - 25;
$y = $bbox[1] + (imagesy($image)) - ($bbox[5] / 2) - 5;
编辑右下角:

 $x = $bbox[0] + (imagesx($image)) - ($bbox[4] / 2) - 130;
 $y = $bbox[1] + (imagesy($image)) - ($bbox[5] / 2) - 30;

好啊让我试试这个,在图像里面?你可以增加25和5来改变位置。我希望这能起到一些指导作用。其余的由你承担:)