X、Y 坐标在干预图像中无法正常工作

问题描述 投票:0回答:1

使用PHP 我正在尝试添加水印图像, 我正在使用干预图像库来实现同样的目的

我需要在右侧添加水印,实际上是图像的右下部分

但是我的 XY 坐标将水印放置在图像之外

这是我的代码

$x = ($targetWidth - $resizedWidth) / 2; // Horizontal padding
        $y = ($targetHeight - $resizedHeight) / 2; // Vertical padding

$originalImage->resize($resizedWidth, $resizedHeight, function ($constraint) {
        $constraint->aspectRatio();
    });

// Create a new canvas with the target dimensions and fill it with white color
$newImage = Image::canvas($targetWidth, $targetHeight, '#FF0000');

// Paste the resized image onto the new canvas at the calculated position
$newImage->insert($originalImage, 'top-left', (int)$x, (int)$y);`

有什么帮助吗?

php image image-resizing watermark intervention
1个回答
0
投票

使用X、Y坐标时,确保水印位置保持在中心 我现在看到了它的“左上角”。这可能是一个障碍。

尝试

$newImage->insert($originalImage, 'center', (int)$x, (int)$y);
© www.soinside.com 2019 - 2024. All rights reserved.