imagemagick (legacy) center, resize, move, crop watermark [closed]

So i have imagemagick Version: ImageMagick 6.9.11-60

To make the process easier I created a ready png file with a repeating pattern at the right angle, with the right transparency which is always larger than input image to cover it. Unfortunately I am not able to make it work.I described what I want to achieve

1. I have an input image (image1) and a watermark (watermark.png). Watermark is a ready mesh with a repeating watermark with the appropriate transparency. Its length and width are always greater than the length and width of image1

2. Now I want to apply this watermark to the center of image1 and the center of watermark1

3. The next step is to be able to reduce the size of the watermark by for example 20% . The dimensions of image1 cannot be changed. The watermark should still be centered after reducing the dimensions.

4. the next step is to move the watermark by a certain number of pixels x and y

5. The last step is to cut out the unnecessary part of the watermark so that only the input image with the watermark remains.

Ideally, it would be possible to do all of this in one query where I can provide parameters such as:

  • input image
  • watermark image
  • output image
  • by how many percent to reduce the watermark
  • by how many pixels X and Y to move the watermark

[EDIT]
in reference to the question I am attaching an example watermark and an image to apply the watermark to.
The wtarmark is already prepared with the appropriate transparency, shadows. The images to which I will apply the watermark are of different sizes and in different aspects but they will always fit within the watermark grid as in the images above
ok

10

I managed to cobble something together that more-or-less does the job. It reads the image files from the server, and stores the output on the server as well. It looks like this:

function applyWatermark(string $imagePath,
                        string $watermarkPath,
                        string $outputPath,
                        int $reductionInPercent,
                        int $offsetX,
                        int $offsetY): void
{
    // get both image and watermark
    $image     = new Imagick($imagePath);
    $watermark = new Imagick($watermarkPath);
    // resize the watermark
    $newWidth  = 0.01 * (100 - $reductionInPercent) * $watermark->getImageWidth();
    $newHeight = 0.01 * (100 - $reductionInPercent) * $watermark->getImageHeight();
    $watermark->resizeImage($newWidth, $newHeight, Imagick::FILTER_QUADRATIC, 1);
    // center the offsets
    $offsetX  -= 0.5 * ($watermark->getImageWidth()  - $image->getImageWidth());
    $offsetY  -= 0.5 * ($watermark->getImageHeight() - $image->getImageHeight());
    // composite watermark into image
    $image->compositeImage($watermark, Imagick::COMPOSITE_OVER, $offsetX, $offsetY);
    // generate output
    $image->writeImage($outputPath);
}

I think you can look up what the various Imagick methods exactly do in the documentation, but I added some comments to clarify them.

All paths have to be absolute paths, and the three other settings are integers. A use case could be:

applyWatermark(__DIR__ . '/dog.jpg',
               __DIR__ . '/watermark.png',
               __DIR__ . '/output.jpg',
               10.0,
               rand(-25, 25),
               rand(-25, 25));

Here the images and output are stored in the same location as the PHP script. The watermark is reduced by 10% and the offset x and y randomly moved by up to 25 pixels in either direction. The result looks like this:

Recognized by PHP Collective

1

Here is a short method in Imagemagick using -distort SRT with a computed viewport to do the cropping. The viewport is a global artifact, so it is stored past the composite where the two input images have been removed and their dimensions lost.

X=-50
Y=-50
magick 
watermark.png image.jpg 
-set option:distort:viewport "%[fx:v.w]x%[fx:v.h]+%[fx:0.5*(u.w-v.w)+$X]+%[fx:0.5*(u.h-v.h)+$Y]" 
-geometry +$X+$Y -gravity center -compose dstover -composite +repage 
-virtual-pixel White -distort SRT 0 +repage x.png

ADDITION

Here is an alternate method that uses -flatten, but shifts the background using -set page in the opposite direction as above.

X=-50
Y=-50
magick 
( image.jpg -set page "+0+0" -set option:ww %w -set option:hh %h ) 
( watermark.png -set page "+%[fx:-w/2+ww/2-($X)]+%[fx:-h/2+hh/2-($Y)]" ) 
-background none -flatten y.png

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật