Page 1 of 1

[SOLVED]: Resizing/Cropping based on info from another image

Posted: 2019-02-11T03:31:51-07:00
by LDAsh
Leading on from this topic:-
viewtopic.php?f=1&t=35471
and very similar to concepts discussed here:-
https://www.imagemagick.org/discourse-s ... hp?t=33209

Although, the condition is that it's simply a Windows BAT file and using IM6, would not involve any fancy scripting environment.

I would like to crop/resize an image to match the dimensions of another image, since the exact resolution could never be known for each case.
Although not involving fancy programming, storing and then retrieving info from a TXT file might do the trick? If IM has such a function?
I honestly have no idea but ideally it would be within one command and not involve extras, if it's possible at all?

Something like this ridiculous fantasy example:-
"convert input.png -resize(%w="match.png"x%h="match.png") output.png"
The fantasy result would be that output.png would be input.png but with the resolution of match.png.

Re: Resizing/Cropping based on info from another image

Posted: 2019-02-11T05:45:19-07:00
by snibgo

Code: Select all

for /F "usebackq" %%L in (`%IM%identify ^
  -format "MYSIZE=%%wx%%h" ^
  match.png`) do set %%L

echo MYSIZE=%MYSIZE%

%IM%convert input.png -resize %MYSIZE% output.png
This makes output.png fit into a box the same size as match.png. Use "!" if you want the exact size.

Re: Resizing/Cropping based on info from another image

Posted: 2019-02-11T06:31:45-07:00
by LDAsh
Wow, too awesome. Got the resize and crop happening, and figured out how to separate the X and Y values all by myself. I guess I can just do ~unlimited values for and from whatever I want, it seems, anything I can get out of identify and into anything that can be fed a number. You've just helped me open up a whole bunch of new possibilities.
Very powerful stuff, cheers snibgo!