Page 1 of 1

Caption Operation Takes 3 Seconds

Posted: 2016-08-03T10:33:41-07:00
by ecomp2016
Hi All,

Is there a way to make the caption operation more efficient in ImageMagick? I'm creating a new image with a caption to composite onto the base image since it does not appear there is a way to position a caption directly on the base image in a specific location with a specified rendering size?

The code:

Code: Select all

cd "C:\Program Files\ImageMagick-7.0.2-Q8"
magick convert -size 980x1828 -font Arial -pointsize 54 -background transparent -fill black caption:"@pokemon.txt" rofl_arial.png
Contents of pokemon.txt (this is just a cool story and is totally NOT real):
Today is the big day... capture a pokemon time they said. We instead ran over another player while driving. The idiot decided to cross the road to capture a wild Chansey. Little did he realize that I was trying to capture a Snorlax around the same location. The difference being that I was driving on the interstate which no one should be walking on. It's illegal. Regardless, Chansey does not show his face much, so you know, it was worth the risk to the player. Unfortunately, I ran him over and got arrested. But at least I caught my wild Snorlax. What a great day. My pokemon collection grows.

Despite the fact that I am now writing this from a jail cell, my Obama phone has not been confiscated, and I can continue to grow my Pokemon collection. No one and nothing will stop me.

If I had to do it all over again, I totally would. Another life is not worth as much as the augmented experience of capturing a wild Pokemon. There is nothing else in the world like it, and there's nothing else worth
It takes 3 seconds to create an image with a transparent background using the huge section of text posted above using ImageMagick. This may not seem like a long time, but our GDI implementation in our C# web application takes .7 seconds to composite multiple images on the main image template, add a large text section to a specified area of the image, and draw other strings on the image that do NOT require wrapping. And, it produces two pages of output containing our resulting images.

ImageMagick takes 4 seconds to complete the rendering of just one page (caption, composite, and draw string operations). That means that ImageMagick takes more than 8 times longer to complete the same operations that GDI performs in less than a second. ASP.NET web applications should not be using GDI according to Microsoft, but there doesn't appear to be a more efficient alternative.

Breakdown of the time it takes ImageMagick (milliseconds):
Draw text string onto image: 114 MS
Create caption image (with specified width and height) and then composite it on the original with a specified position: 2859 MS
Overlay 2 images: 777 MS
Is it possible to speed up the caption operation using ImageMagick, or is this library just not very efficient with text operations? Also, allowing the image to automatically resize based on how tall the text from a caption is seems to be an expensive operation as well and just seems too slow.

Sorry if this sounds a bit harsh, but I'm looking for a feasible efficient alternative to GDI, and so far, my benchmarks have shown that for our purposes, ImageMagick isn't very quick or efficient.

Any help is appreciated.

Re: Caption Operation Takes 3 Seconds

Posted: 2016-08-03T12:27:16-07:00
by snibgo
Try it with "pango:" instead of "caption:". For me, it's about four times as fast.

Re: Caption Operation Takes 3 Seconds

Posted: 2016-08-03T14:51:31-07:00
by ecomp2016
That is much faster! However, why do I have to adjust the FontPointsize property to 43 for the text to fit?

Why is there that huge of a difference in speed between caption and pango?

Re: Caption Operation Takes 3 Seconds

Posted: 2016-08-03T15:16:48-07:00
by ecomp2016
Also, how do I send in the path for the custom font to use with Pango? It looks like it wants the name of a font only. I cannot seem to pass it a font-file path like I could with caption.

Re: Caption Operation Takes 3 Seconds

Posted: 2016-08-03T15:53:01-07:00
by snibgo
I think "caption:" and "label:" were designed for short pieces of text for captions and labels. But "pango:" was designed as a form of cut-down HTML, so for larger cunks of text. Any system can be used for either purpose, but design decisions may favour the originl goals.

I think fonts are handled by the Pango delegate, rather than IM core code, so won't follow the usual IM conventions. Note that you can use tags:

Code: Select all

<span size="50000" font="Nyala">Today is the big day... capture a pokemon time they said. We instead ran over another player while driving. The idiot decided to cross the road to capture a wild Chansey. Little did he realize that I was trying to capture a Snorlax around the same location. The difference being that I was driving on the interstate which no one should be walking on. It's illegal. Regardless, Chansey does not show his face much, so you know, it was worth the risk to the player. Unfortunately, I ran him over and got arrested. But at least I caught my wild Snorlax. What a great day. My pokemon collection grows. 

Despite the fact that I am now writing this from a jail cell, my Obama phone has not been confiscated, and I can continue to grow my Pokemon collection. No one and nothing will stop me. 

If I had to do it all over again, I totally would. Another life is not worth as much as the augmented experience of capturing a wild Pokemon. There is nothing else in the world like it, and there's nothing else worth</span>
"Nyala" is a font installed on my (Windows 8.1) computer.

More about pango in IM: http://www.imagemagick.org/Usage/text/#pango

Re: Caption Operation Takes 3 Seconds

Posted: 2016-08-11T07:56:37-07:00
by ecomp2016
pango takes 274MS to render whereas caption takes 2859MS. It's 10 times faster, but is there a way to get it to render even faster?