Any chance to improve the performace of this "-compose" cmd?

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?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Any chance to improve the performace of this "-compose" cmd?

Post by fmw42 »

I am not sure why you are having trouble with Anthony's method. What version of IM are you using? Type the following: identify -version

If your IM is too old, perhaps you do not have -layers. However, if you do, you can do the following:

convert \( -size 475x873 xc:black \) \( cone.png -resize 30x30 \) \
\( -clone 1 -colorize 40% -repage +23+67 \) \
\( -clone 1 -colorize 40% -repage +75+789 \) \
\( -clone 1 -colorize 40% -repage +76+297 \) \
\( -clone 1 -colorize 40% -repage +256+91 \) \
\( -clone 1 -colorize 20% -repage +91+37 \) \
\( -clone 1 -colorize 20% -repage +57+92 \) \
\( -clone 1 -colorize 20% -repage +10+24 \) \
\( -clone 1 -colorize 20% -repage +2+357 \) \
\( -clone 1 -colorize 90% -repage +2+74 \) \
\( -clone 1 -colorize 90% -repage +87+36 \) \
\( -clone 1 -colorize 90% -repage +37+16 \) \
\( -clone 1 -colorize 90% -repage +46+24 \) \
-delete 1 -compose screen -layers flatten canvas_new1.png

Or this should be slightly faster as it does not recreate the -colorization over and over

convert \( -size 475x873 xc:black \) \
\( cone.png -resize 30x30 \) \
\( -clone 1 -colorize 40% \) \
\( -clone 1 -colorize 20% \) \
\( -clone 1 -colorize 90% \) \
\( -clone 2 -repage +23+67 \) \
\( -clone 2 -repage +75+789 \) \
\( -clone 2 -repage +76+297 \) \
\( -clone 2 -repage +256+91 \) \
\( -clone 3 -repage +91+37 \) \
\( -clone 3 -repage +57+92 \) \
\( -clone 3 -repage +10+24 \) \
\( -clone 3 -repage +2+357 \) \
\( -clone 4 -repage +2+74 \) \
\( -clone 4 -repage +87+36 \) \
\( -clone 4 -repage +37+16 \) \
\( -clone 4 -repage +46+24 \) \
-delete 1-4 -compose screen -layers flatten canvas_new2.png


You will have to put in your directory paths as relevant. I checked the above and it works for me.

Note the ending backslashes are Unix line continuation markers and are needed only if you write this as I have on multiple lines. If you are on windows, then you will need to use other line continuation markers and leave off all the backslashes. See http://www.imagemagick.org/Usage/api/#windows
Da_Vinci

Re: Any chance to improve the performace of this "-compose" cmd?

Post by Da_Vinci »

"identify -version" did not return anything :shock:
So I checked the website of my host (1&1): they state that IM not preinstalled :shock:
Well, then wtf does it seem to work for me at all?

They have a help page for the installation of IM, though. (v4.2.9 or earlier they say)
http://translate.google.com/translate?u ... n&ie=UTF-8

My own local server is powered by 10.5 OSX Leopard.
(But I haven't yet figured how to install IM there :? working on this, though…)

Anyway, that last command looks like it's exactly what I was looking for! :D :D
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Any chance to improve the performace of this "-compose" cmd?

Post by fmw42 »

IM 4.2.9 is years old if that is what you really have. IM is now at 6.4.1-8

You can try typing: convert -list configure and see if that reports. If so, it will have the release number.

If your IM is really that old, you may not be able to use -layers and will need to go back to the other earlier methods I supplied. Let me know and I will convert the example to one of the other forms.


IM binary installs are at: http://www.imagemagick.org/script/binar ... php#macosx

IM source install are at: http://www.imagemagick.org/download/www ... .html#unix

and install notes are are also at: http://www.imagemagick.org/script/advan ... lation.php

I am on Mac OSX Tiger. I used to install the binaries, but I have now been installing from source. If you install from source, you can do it manually or use MacPorts or Fink to help. I ended up learning to do it manually. In any case you will need to install the delegate libraries to use tif, png, jpg etc. They can be found at: http://www.imagemagick.org/download/delegates/

I made some notes a long time ago. You can see them at: viewtopic.php?f=1&t=10442&start=0&st=0& ... c+OS+Tiger
Da_Vinci

Re: Any chance to improve the performace of this "-compose" cmd?

Post by Da_Vinci »

[Edit: This post is no more true! See my next one please!]
fmw42 wrote:IM 4.2.9 is years old if that is what you really have. IM is now at 6.4.1-8
Well, then this is ridiculous. Seriously WTF? :shock:
I'll try to install an up-to-date version of IM and see if it works.
This is more than ridiculous. At the same time they do support PHP5 and MySQL5 though. And then that pre-historic IM :shock:
fmw42 wrote:You can try typing: convert -list configure and see if that reports. If so, it will have the release number.
The only stuff it returns is:

Code: Select all

WEBSITE http://www.imagemagick.org
fmw42 wrote:If your IM is really that old, you may not be able to use -layers and will need to go back to the other earlier methods I supplied. Let me know and I will convert the example to one of the other forms.
I don't think that this would be really needed. As I already mentioned this not (solely) meant to be a private project but is meant to become an open source project. So focussing on my own (totally sucking in case of IM) setup wouldn't make too much sense.

And thank you very much for the installation info! I'll definitely give it a try. :mrgreen:
Last edited by Da_Vinci on 2008-06-20T18:01:08-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Any chance to improve the performace of this "-compose" cmd?

Post by fmw42 »

If you are doing this with PHP, you cannot just type the command line

convert -list configure

or

identify -version

Try creating a .php page with just

<?php
system("/usr/local/bin/convert -version");
?>

or

<?php
$IM_version=shell_exec("/usr/local/bin/convert -version");
echo $IM_version
?>


If this does not work, you need to find out where IM is installed. Possibly change /usr/local/bin to /usr/bin

I went through a similar problem with my ISP, Godaddy, to get instructions on how to find out the IM version. At least they knew they had IM installed.
Da_Vinci

Re: Any chance to improve the performace of this "-compose" cmd?

Post by Da_Vinci »

Okay, facts have changed significally:
1. 1&1 seems to have the latest IM installed! (I blame 1&1's online help sites which are total crap and often uncomplete or even wrong!)
2. "convert -list configure" and "identify -version" seem to have failed due to my use of PHP's "exec();" "shell_exec()" seems to work, though. (see output below)

convert -list configure:

Code: Select all

Path: /usr/lib/ImageMagick-6.2.4/config/configure.xml Name Value ------------------------------------------------------------------------------- CC gcc CFLAGS -g -O2 -Wall -pthread CONFIGURE ./configure --prefix=/usr --mandir=${prefix}/share/man --infodir=${prefix}/share/info --with-gs-font-dir=/usr/share/fonts/type1/gsfonts --with-magick-plus-plus --enable-shared --enable-lzw --without-dps --without-fpx --without-perl --with-perl-options=INSTALLDIRS=vendor --x-includes=/usr/include/X11 --x-libraries=/usr/lib/X11 COPYRIGHT Copyright (C) 1999-2005 ImageMagick Studio LLC CPPFLAGS -I/usr/include CVS_BRANCH_TAG HEAD CXX g++ CXXFLAGS -pthread DEFS -DHAVE_CONFIG_H DISTCHECK_CONFIG_FLAGS --prefix=/usr --mandir=${prefix}/share/man --infodir=${prefix}/share/info --with-gs-font-dir=/usr/share/fonts/type1/gsfonts --with-magick-plus-plus --enable-shared --enable-lzw --without-dps --without-fpx --without-perl --with-perl-options=INSTALLDIRS=vendor --x-includes=/usr/include/X11 --x-libraries=/usr/lib/X11 EXEC-PREFIX /usr HOST i686-pc-linux-gnu LDFLAGS -L/usr/lib -L/usr/lib/X11 -lfreetype -lz -L/usr/lib LIB_VERSION 0x624 LIB_VERSION_NUMBER 6,2,4,5 LIBS -lMagick -llcms -ltiff -lfreetype -ljasper -ljpeg -lpng -lXext -lXt -lSM -lICE -lX11 -lbz2 -lxml2 -lz -lpthread -lm -lpthread NAME ImageMagick PCFLAGS PREFIX /usr QuantumDepth 16 RELEASE_DATE 02/10/07 VERSION 6.2.4 WEBSITE http://www.imagemagick.org 
Sorry 1&1 for blaming you :(

Now as i looks like I'm having an up-to-date IM I'll try to get this latest command to work:

Code: Select all

convert \( -size 475x873 xc:black \) \
\( cone.png -resize 30x30 \) \
\( -clone 1 -colorize 40% \) \
\( -clone 1 -colorize 20% \) \
\( -clone 1 -colorize 90% \) \
\( -clone 2 -repage +23+67 \) \
\( -clone 2 -repage +75+789 \) \
\( -clone 2 -repage +76+297 \) \
\( -clone 2 -repage +256+91 \) \
\( -clone 3 -repage +91+37 \) \
\( -clone 3 -repage +57+92 \) \
\( -clone 3 -repage +10+24 \) \
\( -clone 3 -repage +2+357 \) \
\( -clone 4 -repage +2+74 \) \
\( -clone 4 -repage +87+36 \) \
\( -clone 4 -repage +37+16 \) \
\( -clone 4 -repage +46+24 \) \
-delete 1-4 -compose screen -layers flatten canvas_new2.png
Regarding the continuation markers "\" at the line ends: I'm generating the as one single line without them, so compatibiity should not be a problem.

I'll post my progress and some speed statistics of all the commands mentioned.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Any chance to improve the performace of this "-compose" cmd?

Post by fmw42 »

You have IM 6.2.4.5 and they are now at 6.4.1.9.

I don't know if it is worth it to try to get 1&1 to update their IM. The main issue is whether you can use -layers or not.

According to http://www.imagemagick.org/Usage/anim_mods/#composite, layers came into play at version 6.3.3-7. So your version is too old for that approach.

Try

convert \( -size 475x873 xc:black \) \
\( cone.png -resize 30x30 \) \
\( -clone 1 -colorize 40%,40%,40% \) \
\( -clone 1 -colorize 20%,20%,20% \) \
\( -clone 1 -colorize 90%,90%,90% \) \
\( -clone 0 -clone 2 -compose screen -geometry +23+67 -composite \) -swap 0,5 +delete \
\( -clone 0 -clone 2 -compose screen -geometry +75+789 -composite \) -swap 0,5 +delete \
\( -clone 0 -clone 2 -compose screen -geometry +76+297 -composite \) -swap 0,5 +delete \
\( -clone 0 -clone 2 -compose screen -geometry +256+91 -composite \) -swap 0,5 +delete \
\( -clone 0 -clone 3 -compose screen -geometry +91+37 -composite \) -swap 0,5 +delete \
\( -clone 0 -clone 3 -compose screen -geometry +57+92 -composite \) -swap 0,5 +delete \
\( -clone 0 -clone 3 -compose screen -geometry +10+24 -composite \) -swap 0,5 +delete \
\( -clone 0 -clone 3 -compose screen -geometry +2+357 -composite \) -swap 0,5 +delete \
\( -clone 0 -clone 4 -compose screen -geometry +2+74 -composite \) -swap 0,5 +delete \
\( -clone 0 -clone 4 -compose screen -geometry +87+36 -composite \) -swap 0,5 +delete \
\( -clone 0 -clone 4 -compose screen -geometry +37+16 -composite \) -swap 0,5 +delete \
\( -clone 0 -clone 4 -compose screen -geometry +46+24 -composite \) -swap 0,5 +delete \
-delete 1-5 canvas_new3.png


Note -colorize has been working strangely. There are some bug reports. Using one value caused the spots to be red on my current version of IM. So repeating them for red, green and blue makes it preserve white. On your older system this may not be necessary.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Any chance to improve the performace of this "-compose" cmd?

Post by Bonzo »

You can write the code like this which makes it easer to read than one long line:

Code: Select all

$cmd = " \( -size 475x873 xc:black \) ".
" \( cone.png -resize 30x30 \)  ".
" \( -clone 1 -colorize 40% \)  ".
" \( -clone 1 -colorize 20% \)  ".
" \( -clone 1 -colorize 90% \)  ".
" \( -clone 2 -repage +23+67 \)  ".
" \( -clone 2 -repage +75+789 \)  ".
" \( -clone 2 -repage +76+297 \)  ".
" \( -clone 2 -repage +256+91 \)  ".
" \( -clone 3 -repage +91+37 \)  ".
" \( -clone 3 -repage +57+92 \)  ".
" \( -clone 3 -repage +10+24 \) ".
" \( -clone 3 -repage +2+357 \) ".
" \( -clone 4 -repage +2+74 \) ".
" \( -clone 4 -repage +87+36 \) ".
" \( -clone 4 -repage +37+16 \) ".
" \( -clone 4 -repage +46+24 \) ".
" -delete 1-4 -compose screen -layers flatten ";

shell_exec(" convert $cmd canvas_new2.png");
Da_Vinci

Re: Any chance to improve the performace of this "-compose" cmd?

Post by Da_Vinci »

Bonzo wrote:You can write the code like this which makes it easer to read than one long line: […]
I'm actually doing it with an array holding the coordinates and opacities and a "foreach() {}" for the command generation. :wink:
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Any chance to improve the performace of this "-compose" cmd?

Post by anthony »

WARNING: you need to specify a -fill black otherwise you are just assuming the fill color is black (which is the default, but don't 'assume'.

As the famous British comedian said...
Benny Hill wrote:Assume(n): Making and ASS out of U and ME.
You can generate the command using a foreach loop.

OR you can generate a seperate overlay image complete with '-page' position and opacity, and feed it as a MIFF:- image pipeline into your layering command.
For an example of this see
http://imagemagick.org/Usage/layers/#example
Just replace the inside of the loop with the appropriate adjustment and -repage options and output a MIFF:- image into the pipeline.
Of course as the image is nolonger being cloned, but read in, it will use seperate memory for each image, and need to read in each image, which slows it up again.

The command line generation method is probably faster, or better use a Perl API, with appropriate cloning for total control of the whole process within the loop.

That would probably be even faster as you will also remove all the 'command line parsing' that IM needs to do, as well as ensure you do not reach any SHELL command line length limits.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply