Page 1 of 1

PHP Resize based on overlaying image

Posted: 2019-09-02T07:00:51-07:00
by pbennett87
I am having to use system commands in PHP, how would I resize the top layer to fit both height and width (even if the top layer is cropped slightly) it also needs to keep aspect ratio.

system('convert background.png overlay.php \
\( -clone 0 -alpha extract \) \
\( -clone 0 -clone 1 -compose multiply -composite \) \
-delete 0,1 +swap -alpha off -compose copy_opacity -composite overlay_result.png');

I am really new to imagemagick so any help would be grateful, kindest regards.

Re: PHP Resize based on overlaying image

Posted: 2019-09-02T07:37:00-07:00
by snibgo
When resizing one image to the size of another, if they have different aspect ratios then you have a choice of either resizing exactly or keeping the original aspect ratio. You can't do both.

Please show sample input images. ".php" is not a format known to IM.

Re: PHP Resize based on overlaying image

Posted: 2019-09-02T07:49:23-07:00
by pbennett87
Hi snibgo, sorry the format is actually PNG that is a typo. Please can you show me an example for both (exact resize, and keeping aspect ratio)? Both would be useful, I thought we could possibly resize but keeping the aspect ratio > then crop ? then overlay?

Re: PHP Resize based on overlaying image

Posted: 2019-09-02T07:57:58-07:00
by snibgo
For exact resizing, and other options, see http://www.imagemagick.org/script/comma ... p#geometry

Yes, after resizing, one image may be cropped. Or the other could be extended. See options on http://www.imagemagick.org/script/comma ... ptions.php

Re: PHP Resize based on overlaying image

Posted: 2019-09-02T08:00:09-07:00
by pbennett87
So if my small image is 500x800px and my large image is 2000x2000 I should probably use
500x800^ ?

Re: PHP Resize based on overlaying image

Posted: 2019-09-02T09:18:45-07:00
by snibgo
That depends on what you want. I encourage you to try it out:

Code: Select all

magick -size 2000x2000 xc: -resize 500x800^ info:

xc: XC 800x800 800x800+0+0 16-bit sRGB 1.844u 0:00.250
The result is 800x800 pixels.