Consolidating Commands

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
dmfelder
Posts: 9
Joined: 2014-03-13T12:04:17-07:00
Authentication code: 6789

Consolidating Commands

Post by dmfelder »

Hello All! I have a project that requires me to perform 5 different commands, but I'm wondering if they can be consolidated because the process takes a while.

I am taking one image (myimagename1), merging the layers and creating a new image (myimagename). Then I am changing the size of the image. Then I am merging the image with a background image. Then I'm resizing it. Then I'm stripping it. Here are my commands:

Code: Select all

Convert "-background", "none", "-layers", "merge", myimagename1, myimagename
                               
Convert "-thumbnail", "2000x4000", "-bordercolor", "none", "-border", "0", myimagename, myimagename
                          
Convert "-composite", mybackground, myimagename, "-geometry", "+500+200", myimagename

Convert myimagename, "-resize", "1000x1000", myimagename
                                   
Convert myimagename, "-strip", myimagename
Is there a way to combine some of these commands?

Again, it works, but it takes a while to complete.

THANKS!
-David
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Consolidating Commands

Post by fmw42 »

In unix, try

Code: Select all

convert myimagename1 \
-background none -flatten \
-thumbnail 2000x4000 \
-bordercolor none -border 0 \
mybackground +swap -geometry +500+200 -composite \
-resize 1000x1000 -strip \
myimagename
or windows I believe it would just be

Code: Select all

convert myimagename1 ^
-background none -flatten ^
-thumbnail 2000x4000 ^
-bordercolor none -border 0 \
mybackground +swap -geometry +500+200 -composite ^
-resize 1000x1000 -strip ^
myimagename
I am not sure why you are adding -bordercolor none -border 0. It adds zero border and seems like a no-op situation to me. You have already specified to flatten the image with transparent background. I have used the simpler -flatten rather than -layers merge. Also -thumbnail and -resize do the same thing, except -thumbnail has a built in -strip.

Note that proper IM syntax has you read a raster image before applying any operations to it.

The use of \ in unix and ^ in windows at the end of a line, allows you to write commands on multiple lines for more readability. In the above cases, you can remove all of them if you do not write to more than one line of text.
dmfelder
Posts: 9
Joined: 2014-03-13T12:04:17-07:00
Authentication code: 6789

Re: Consolidating Commands

Post by dmfelder »

OMG! Wonderful. It takes about 75% less time!!!

You guys are great!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Consolidating Commands

Post by fmw42 »

try removing the -bordercolor none -border 0 and see if that helps and keeps the same output
Post Reply