Referring to the filename with %t makes my code slow?

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
jack-mann
Posts: 16
Joined: 2014-03-15T00:49:44-07:00
Authentication code: 6789

Referring to the filename with %t makes my code slow?

Post by jack-mann »

I found out that this code is about 60% slower:

Code: Select all

convert image_*.png  -background white -gravity center -extent 20400x -crop 400x400  -set "filename:data" "%t_%[fx:page.x/400]"   +repage +adjoin "cropped_%[filename:data].png"
than using a loop (pseudo code):

Code: Select all

for (y=0;y < 34;y++)
{
convert image_{y}.png  -background white -gravity center -extent 20400x -crop 400x400  -set "filename:data" "%[fx:page.x/400]"   +repage +adjoin "cropped_{y}_%[filename:data].png"
}
The reason seems to be in the first case I reference with %t the input image name.
How can this be?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Referring to the filename with %t makes my code slow?

Post by fmw42 »

try adding -ping, so that IM reads only the meta data and not the full image.

convert -ping image_*.png -background white -gravity center -extent 20400x -crop 400x400 -set "filename:data" "%t_%[fx:page.x/400]" +repage +adjoin "cropped_%[filename:data].png"

see
http://www.imagemagick.org/Usage/basics/#controls
jack-mann
Posts: 16
Joined: 2014-03-15T00:49:44-07:00
Authentication code: 6789

Re: Referring to the filename with %t makes my code slow?

Post by jack-mann »

ping does not help.. also all cropped images are all black now....
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Referring to the filename with %t makes my code slow?

Post by fmw42 »

Sorry about the -ping. Bad suggestion.

Without the external loop, I think IM convert will try to read all the images into memory and process them all, thus doubling or tripling the memory usage. You may be running out of memory and thus IM using disk space to supplement. With the loop, it will only read one image, process it and then write it, so the memory requirements are much smaller.
jack-mann
Posts: 16
Joined: 2014-03-15T00:49:44-07:00
Authentication code: 6789

Re: Referring to the filename with %t makes my code slow?

Post by jack-mann »

I would also assume that the second cmd is first putting all input images in memory.
there is probably no way to hint the first command to behave memory-wise like the second for loop command?
Since of a stream pipeline?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Referring to the filename with %t makes my code slow?

Post by fmw42 »

I would also assume that the second cmd is first putting all input images in memory.
No, then second command with the loop only processes one image at a time and thus only one image in memory at a time (plus any intermediates needed for processing and the output). I think the first command tries to read all the images first before processing each one.
Post Reply