Page 1 of 1
use dimensions from one image to resize another
Posted: 2008-09-30T12:21:59-07:00
by mrmernan
..trying to do resize img2 using img1's dimensions
i.e. kinda like; convert -resize img2.jpg img1.%w\ximg1.%h!
..tried setting the %w %h vars w/ -label, -size, etc, but cant get it to store them
Re: use dimensions from one image to resize another
Posted: 2008-09-30T18:40:34-07:00
by fmw42
mrmernan wrote:..trying to do resize img2 using img1's dimensions
i.e. kinda like; convert -resize img2.jpg img1.%w\ximg1.%h!
..tried setting the %w %h vars w/ -label, -size, etc, but cant get it to store them
You can use two lines: get size, then use it:
size=`convert rose: -format "%wx%h" info:`
convert logo: -resize "$size" logo_rose.png
or combine them into one line:
convert logo: -resize "$(convert rose: -format "%wx%h" info:)" logo_rose.png
Examples above use rose: and logo: built-in images. So you can try it.
Re: use dimensions from one image to resize another
Posted: 2008-10-01T10:11:15-07:00
by mrmernan
thanks! ..couldnt get your example to work via our fussy linux/tcsh environment (when used verbatim) , but your basic idea did inspire me to this;
convert infile2.jpg -resize `identify infile1.jpg -format "%wx%h!"` outfile.jpg
thanks again!
Re: use dimensions from one image to resize another
Posted: 2008-10-01T18:37:24-07:00
by anthony
Eventually (probably with IM v7) you will be able to do this more directly, but for now you will need to use two commands.
An API interface, like PerlMagick, IMagikc, or Rmagick, can do this more directly.
Re: use dimensions from one image to resize another
Posted: 2008-10-01T20:09:29-07:00
by fmw42
mrmernan wrote:thanks! ..couldnt get your example to work via our fussy linux/tcsh environment (when used verbatim) , but your basic idea did inspire me to this;
convert infile2.jpg -resize `identify infile1.jpg -format "%wx%h!"` outfile.jpg
thanks again!
Yes, identify and convert can both be used to get string formats. So
convert infile2.jpg -resize `convert infile1.jpg -format "%wx%h!" info:` outfile.jpg
should work also.
On some systems, at least from what I can tell,
`...` is the same as $(...)
You may get some faster results adding -ping, so that the image does not have to be read in.
convert infile2.jpg -resize `identify -ping -format "%wx%h!" infile1.jpg` outfile.jpg
See
http://www.imagemagick.org/Usage/basics/#controls