combine crop and scale into one command?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
jedierikb
Posts: 20
Joined: 2012-12-13T13:59:27-07:00
Authentication code: 6789

combine crop and scale into one command?

Post by jedierikb »

Currently, I am using two commands, and an intermediate temporary file, to crop and scale images.

Code: Select all

convert src.jpg -crop 50%x50%+10+10 intemediate.jpg
convert intemediate.jpg -distort Resize 100\!x1000\! output.png
Is there a good way to combine these two commands into one command and to prevent the writing of the unnecessary extra file?

Thanks,
Erik
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: combine crop and scale into one command?

Post by snibgo »

convert src.jpg -crop 50%x50%+10+10 -distort Resize 100\!x1000\! output.png
snibgo's IM pages: im.snibgo.com
User avatar
GreenKoopa
Posts: 457
Joined: 2010-11-04T17:24:08-07:00
Authentication code: 8675308

Re: combine crop and scale into one command?

Post by GreenKoopa »

You may want a +repage after the -crop.
http://www.imagemagick.org/Usage/crop/#crop_repage

Lossy formats, such as jpeg, are not ideal for intermediate files.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: combine crop and scale into one command?

Post by fmw42 »

convert src.jpg -crop 50%x50%+10+10 -distort Resize 100\!x1000\! output.png

I believe that you only need one \! at the end, thought I suspect that will not hurt otherwise. Also GreenKoopa is right, you need to remove the virtual canvas after a crop if saving to PNG, unless you need to keep it for some reason.

convert src.jpg -crop 50%x50%+10+10 +repage -distort Resize 100x1000\! output.png
Post Reply