Page 1 of 1

Break complex command into simpler steps...

Posted: 2015-12-22T04:12:29-07:00
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!

Re: Break complex command into simpler steps...

Posted: 2015-12-22T10:41:47-07:00
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

Re: Break complex command into simpler steps...

Posted: 2015-12-22T23:32:12-07:00
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

Re: Break complex command into simpler steps...

Posted: 2015-12-23T00:05:39-07:00
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.

Re: Break complex command into simpler steps...

Posted: 2015-12-23T01:04:44-07:00
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.

Re: Break complex command into simpler steps...

Posted: 2015-12-23T09:35:49-07:00
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

Re: Break complex command into simpler steps...

Posted: 2015-12-23T09:54:10-07:00
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.