ImageMagick 将水印从左上角移动到右下角?
ImageMagick move watermark from top left to bottom right?
我可以在左上角的图片上添加水印,我该如何更改它以便它添加到右下角?
这是我当前的代码:
$watermark = new Imagick();
$watermark->readImage("images/watermark_boxart.png");
$im->compositeImage($watermark, imagick::COMPOSITE_OVER, 3, 3);
谢谢
您正在 (3,3) 处设置水印。您需要通过相应地放置这些数字将其设置在右下角。
Methodology:
- Calculate width and height on $im [$im_height, $im_width]
- Calculate width and height of $watermerk [$wm_height, $wm_width]
- Find the coordinates to place the watermark at via calculation of differences in dimensions
- Create composite with calculated locations
代码:
$im_d = $im->getImageGeometry();
$im_w = $im_d['width'];
$im_h = $im_d['height'];
$watermark = new Imagick();
$watermark->readImage("images/watermark_boxart.png");
$watermark_d = $watermark->getImageGeometry();
$watermark_w = $watermark_d['width'];
$watermark_h = $watermark_d['height'];
$margin = 3;
$x_loc = $im_w - $watermark_w - $margin;
$y_loc = $im_h - $watermark_h - $margin;
$im->compositeImage($watermark, imagick::COMPOSITE_OVER, $x_loc, $y_loc);
我可以在左上角的图片上添加水印,我该如何更改它以便它添加到右下角?
这是我当前的代码:
$watermark = new Imagick();
$watermark->readImage("images/watermark_boxart.png");
$im->compositeImage($watermark, imagick::COMPOSITE_OVER, 3, 3);
谢谢
您正在 (3,3) 处设置水印。您需要通过相应地放置这些数字将其设置在右下角。
Methodology:
- Calculate width and height on $im [$im_height, $im_width]
- Calculate width and height of $watermerk [$wm_height, $wm_width]
- Find the coordinates to place the watermark at via calculation of differences in dimensions
- Create composite with calculated locations
代码:
$im_d = $im->getImageGeometry();
$im_w = $im_d['width'];
$im_h = $im_d['height'];
$watermark = new Imagick();
$watermark->readImage("images/watermark_boxart.png");
$watermark_d = $watermark->getImageGeometry();
$watermark_w = $watermark_d['width'];
$watermark_h = $watermark_d['height'];
$margin = 3;
$x_loc = $im_w - $watermark_w - $margin;
$y_loc = $im_h - $watermark_h - $margin;
$im->compositeImage($watermark, imagick::COMPOSITE_OVER, $x_loc, $y_loc);