Page 1 of 1

Help with slowdown and combining commands...

Posted: 2011-08-31T07:38:52-07:00
by mcapraro
hi there,
i've been using ImageMagick in testing and on a production server and it has been working fine. Now i just moved to a new server that is supposed to be better overall and noticing extreme slow downs in ImagMagick convert performance. i am running this from a php script, here are is what i am doing:

Code: Select all

// create the color strokes
$cmd = "$convertCMD -size 1024x713 xc:none -draw @temp/".$uniqueFileName."_color_data.txt temp/".$uniqueFileName."_color.png";
echo shell_exec(escapeshellcmd($cmd));

// create the mask
$cmd = "$convertCMD -size 1024x713 xc:black -draw @temp/" . $uniqueFileName . "_data.txt temp/".$uniqueFileName."_mask.png";
echo shell_exec(escapeshellcmd($cmd));

// composite the images
$cmd = "$convertCMD -size 1300x1000 -bordercolor white -border 650x500 $imgname temp/".$uniqueFileName."_color.png temp/".$uniqueFileName."_mask.png -composite -gravity Center frames/picture-frame-1.png -composite -crop 1300x1000+0+0 temp/" . $uniqueFileName . ".jpg";
echo shell_exec(escapeshellcmd($cmd));
$imgname is an existing png file 1024x713 in size. you can download it here http://mcapraro.com/projects/downloads/test.png
the picture-frame image: http://mcapraro.com/projects/downloads/ ... rame-1.png
and the temp data files:
http://mcapraro.com/projects/downloads/ ... c_data.txt
http://mcapraro.com/projects/downloads/ ... r_data.txt

also, as s second request: can anyone help me combine this into one command vs. saving it out as 3 files as i am doing now.

the version i am running is 6.7.2-1 2011-08-30 Q8, on Linux 2.6.18, machine specs GenuineIntel, Intel(R) Xeon(R)CPU L5630 @ 2.13GHz. I recompiled with quantum depth of 8 as i read it might be faster but saw no increase in speed. the conversion can take about a minute and a half, which i would love to be much quicker

thanks in advance, mich

Re: Help with slowdown and combining commands...

Posted: 2011-08-31T09:58:44-07:00
by Bonzo
This worked in about 1/2 of the original time - on my localhost Image created in 2.28799986839 seconds. - Image created in 1.24189996719 seconds.:

Code: Select all

// composite the images
$cmd = "$convertCMD -size 1300x1000 xc:white $imgname -gravity Center -composite ( -size 1024x713 xc:none -draw @".$uniqueFileName."_color_data.txt ) -gravity Center -composite picture-frame-1.png -gravity Center -composite -trim " . $uniqueFileName . ".jpg";
NOTE: On a Linux type server you will need to change the ( and ) to \( and \)

Out of interest why were you creating the mask as it seems OK without and I have removed it - withe the mask I had problem as I only had a black and white image without the colour.

I have also removed the first part with the border and changed the -crop to a -trim althogh it is not doing anything as the image was already at the crop size.

Fred or Anthony can probably tell me where I went wrong with this code that ended up with a black and white image only:

Code: Select all

$cmd = "$convertCMD -size 1300x1000 xc:white $imgname -gravity Center -composite ( -size 1024x713 xc:none -draw @".$uniqueFileName."_color_data.txt ) -gravity Center -composite ( -size 1024x713 xc:black -draw @" . $uniqueFileName . "_data.txt ) -gravity Center -composite picture-frame-1.png -gravity Center -composite -trim " . $uniqueFileName . "1.jpg";
P.S. Probably supposed to have at least one matte or flatten in there somewhere :?

Re: Help with slowdown and combining commands...

Posted: 2011-08-31T10:05:17-07:00
by mcapraro
thanks for the reply Bonzo! the mask data is for erasing that is done by the user, this sample might not be the best to show how that works, but yeah, i had trouble also making the mask work when it was all combined. i will give this a show though, thanks!

Re: Help with slowdown and combining commands...

Posted: 2011-08-31T10:19:24-07:00
by mcapraro
ok, well, i cant achieve those same masking effects with the one-liner, at least not that way. so if anyone has any other ideas..

also, on the server i am on, it seems its the draw commands that are really slowing me down. a ton! is there any reason why parsing the draw commands on this server are so painfully slow and on another they arent? maybe i complied it wrong?

Re: Help with slowdown and combining commands...

Posted: 2011-08-31T10:21:47-07:00
by fmw42
I am not sure what you are trying to do as you did not show an output example. But from your images it looks like you want to put the frame around the yellow picture. Both of these work for me in unix command line.


convert picture-frame-1.png test.png -gravity center -compose dst_over -composite tmp1.png


convert picture-frame-1.png test.png -gravity center -composite tmp1.png


for windows, remove the \ before the parens.


If you need something different, please clarify and show an output if you can.

I am not sure what you are doing with the text. Can you provide the file or show the result, so that I can try to figure out how best to include that. Presumably you can write the text directly on the yellow file without any masks or transparency overlays. You can use -draw or -annotate (or label: or caption:). Perhaps annotate might be faster?

It is possible that you don't have the same fonts. You don't specify any font or pointsize, so it is looking for some default and perhaps cannot find it so looks to find some other.

Re: Help with slowdown and combining commands...

Posted: 2011-08-31T10:35:08-07:00
by Bonzo
The OP has a cream background that he is putting an image onto generated from the text file; this is the enclosed by the frame.

Image removed as OP posted a copy

Re: Help with slowdown and combining commands...

Posted: 2011-08-31T10:37:49-07:00
by mcapraro
hi guys, here is the output of the commands from the first post:
Image

Re: Help with slowdown and combining commands...

Posted: 2011-08-31T10:41:56-07:00
by Bonzo
As you say mich a lot slower on a server:

Your original code - Image created in 56.3894000053 seconds.

My not quite suitable code - Image created in 21.894299984 seconds.

Although still quicker than your server.

Re: Help with slowdown and combining commands...

Posted: 2011-08-31T10:45:13-07:00
by mcapraro
some more info:
the first draw file (http://mcapraro.com/projects/downloads/ ... r_data.txt) contains stroke data generated dynamically by a flash app. the second data file (http://mcapraro.com/projects/downloads/ ... c_data.txt) contains a mask which has additional "erase" strokes so i can remove the color data by just masking it out. i take this and composite it on an image (http://mcapraro.com/projects/downloads/test.png) and then center it in a frame (http://mcapraro.com/projects/downloads/ ... rame-1.png) for the final result (http://mcapraro.com/projects/downloads/test.jpg).

it all works great (thanks ImageMagick!) but, on a new server it is painfully slow (80 seconds to do all this). i thought maybe making this a single command might speed it up but it seems to be slowing it down further. is that possible?

also, could there be something i am not passing during compiling ImageMagick that could cause it o not be as optimized, therefore running slowly?

Re: Help with slowdown and combining commands...

Posted: 2011-08-31T11:05:19-07:00
by fmw42
I have heard cases where systems with multiprocessors that have OpenMP enabled can run slower than with OpenMP disabled. You might look into this. Use

convert -version

to see if you have OpenMP enabled. If so, the recompile IM with OpenMP disabled.


You certainly have a lot of draw commands. That could be slow, but nothing you can do about that.

Are your coordinates relative to the size of the yellow image or relative to the frame size image?

Re: Help with slowdown and combining commands...

Posted: 2011-08-31T11:11:40-07:00
by mcapraro
thanks fmw42, i'll try to compile with openmp disabled. the draw commands are relative to the yellow image

Re: Help with slowdown and combining commands...

Posted: 2011-08-31T11:13:28-07:00
by fmw42
mcapraro wrote:thanks fmw42, i'll try to compile with openmp disabled. the draw commands are relative to the yellow image

OK. I have to leave for an appointment. But later I will try to combine your commands. Though I think the slowdown has to do with something else -- configuration of IM and/or your server. But combining into one command can help some.

Re: Help with slowdown and combining commands...

Posted: 2011-08-31T11:52:04-07:00
by mcapraro
you did it fmw42! wow, thanks soooo much!

this article i think is exactly what i was running into: http://tellgren.com/post/4070254783/tro ... p-on-a-vps

i should have mentioned i was on a VPS, so sorry for the runaround.

still looking for a one liner so i dont have all these files i have to unlink, but for know its executing in 2 seconds vs 78 ;)

Re: Help with slowdown and combining commands...

Posted: 2011-08-31T14:12:45-07:00
by fmw42
You can do it at least two ways.

Method 1: Using clones

convert picture-frame-1.png test.png \
\( -size 1024x713 xc:none -draw "@color_data.txt" \) \
\( -size 1024x713 xc:black -draw "@mask_data.txt" \) \
\( -clone 2 -clone 3 -alpha off -compose copy_opacity -composite \) \
\( -clone 1 -clone 4 -compose over -composite \) \
-delete 1-4 -gravity center -compose over -composite result.png


Method 2: Without clones, so a bit more compact but less easy to follow due to nested parens.

convert picture-frame-1.png \
\( \( -size 1024x713 xc:none -draw "@color_data.txt" \) \
\( -size 1024x713 xc:black -draw "@mask_data.txt" \) \
-alpha off -compose copy_opacity -composite \
test.png +swap -compose over -composite \) \
-gravity center -compose over -composite result.png


You can remove the "continue to next line" ending \ to make this all one line and put it into PHP.

It is just easier to follow as a command line when you break the lines into functional parts.

Re: Help with slowdown and combining commands...

Posted: 2011-08-31T17:11:44-07:00
by mcapraro
wow, thanks once again fmw42, those both work perfectly! thanks for helping me make my app more efficient!