Break complex command into simpler steps...

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
amit1411
Posts: 8
Joined: 2015-08-03T22:24:14-07:00
Authentication code: 1151

Break complex command into simpler steps...

Post by amit1411 »

Hi, I want to break a complex Imagemagic command into small simpler steps. Can someone please help me. We can create some intermediate temp files for intermediate steps. The command is :
convert subject.jpg -colorspace gray ( +clone -blur 0x2 ) +swap -compose divide -composite -linear-stretch 5%x0% -level 0%,100%,0.25 a.png

Here subject.jpg is the source image. I want to break it something like :
convert subject.jpg - colorspace gray a1.png
convert a1.png +clone -blur 0X2 a2.png
etc etc

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

Re: Break complex command into simpler steps...

Post by fmw42 »

Code: Select all

convert subject.jpg -colorspace gray a1.png
convert a1.png -blur 0X2 a2.png 
convert a1.png a2.png +swap -compose divide -composite a3.png
convert a3.png -linear-stretch 5%x0% a4.png
convert a4.png -level 0%,100%,0.25 a.png
But if you just want to get intermediate images from each step you can just use -write statements in the one command line

Code: Select all

convert subject.jpg -colorspace gray -write a1.p ( +clone -blur 0x2 -write a2.png ) +swap -compose divide -composite -write a3.png -linear-stretch 5%x0% -write a4.png -level 0%,100%,0.25 a.png
amit1411
Posts: 8
Joined: 2015-08-03T22:24:14-07:00
Authentication code: 1151

Re: Break complex command into simpler steps...

Post by amit1411 »

Thanks a lot for your response.
Actually I want to convert this command to php code using IMagick. I am still not sure how to create the php script for the third command here :
convert a1.png a2.png +swap -compose divide -composite a3.png
What is it actually doing. Is it possible to further break it and then composite the images to create a3.png?
Thanks,
Amit
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Break complex command into simpler steps...

Post by fmw42 »

It is the same as

Code: Select all

convert a2.png a1.png -compose divide -composite a3.png
or

Code: Select all

composite -compose divide a1.png a2.png a3.png
which cannot be reduce further. See

http://us3.php.net/manual/en/imagick.compositeimage.php

But http://us3.php.net/manual/en/imagick.co ... ompositeop does not list a divide composite option. Perhaps this document is old and there is a newer documents with divide as an option.

Imagick has not been maintained to keep up with Imagemagick. I would suggest you use PHP exec() for the whole command or at least for this one part.
amit1411
Posts: 8
Joined: 2015-08-03T22:24:14-07:00
Authentication code: 1151

Re: Break complex command into simpler steps...

Post by amit1411 »

Thanks. Now I understood the command, but you are right that the "Divide" blend type is not mentioned in IMagic documentation :(
Using exec command is definitely an option but that involves saving the image file we receive from UI to a server location, use exec to run the commands in which more temp files are created and finally output image created on server to be picked and shared back with UI for display. We thought having so many I/O operations will decrease the performance and also we have to take care of concurrent users situation.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Break complex command into simpler steps...

Post by fmw42 »

You can run this whole command line in one PHP exec() command

Code: Select all

convert subject.jpg -colorspace gray ( +clone -blur 0x2 ) +swap -compose divide -composite -linear-stretch 5%x0% -level 0%,100%,0.25 a.png
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Break complex command into simpler steps...

Post by Bonzo »

fmw42's example takes the image modifies it and saves it without any temporary files.

As far as I know Imagick needs the image saving on the server to start with as well.

If on a Linux type server you will need to change ( +clone -blur 0x2 ) to \( +clone -blur 0x2 \)

Imagick is limited in its options and seems to get updated in steps as another developer takes it over.
Post Reply