使用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);`
有什么帮助吗?
使用X、Y坐标时,确保水印位置保持在中心 我现在看到了它的“左上角”。这可能是一个障碍。
尝试
$newImage->insert($originalImage, 'center', (int)$x, (int)$y);