Optimization

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
jam@tigger.ws
Posts: 7
Joined: 2016-06-01T22:44:04-07:00
Authentication code: 1151

Optimization

Post by jam@tigger.ws »

Hi
This is not really a developer question except that the developers did something that broke the way image magic did work.
My requirement is very technical and exact (Text overlay on video captured by Sensoray S2253 cards)

I draw text onto a blank canvas of correct size:
mogrify -pointsize 20 -font Helvetica -define png:format=png32 -fill snow -stroke black -strokewidth 5 -draw text 2,22 "look at the huge telescope" -stroke none -draw text 2,22 "look at the huge telescope" /dev/shm/record12.png

perfect.
file /dev/shm/record12.png /dev/shm/record12.png: PNG image data, 177 x 29, 8-bit/color RGBA, non-interlaced

Now I draw a short line
mogrify -pointsize 50 -font Helvetica -define png:format=png32 -fill snow -stroke black -strokewidth 5 -draw text 2,54 "hi" -stroke none -draw text 2,54 "hi" /dev/shm/record11.png

uh uh
file /dev/shm/record11.png /dev/shm/record11.png: PNG image data, 54 x 69, 8-bit colormap, non-interlaced

I've tried everything I've been able to google, man pages and ask on the users group without any joy.
Currently imagemagick 8:6.8.9.9-7ubunt amd64, imagemagick 8:6.7.7.10-6ubun amd64 works correctly. How do I force behaviour?

On the earlier version I use color "white" here "white" makes greyscale images.
Thanks
James
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Optimization

Post by fmw42 »

First, I would suggest you use convert instead of mogrify if you are processing only one image.

Try putting the required quotes in all your draw command - example follows:

Code: Select all

-draw "text 2,22 'look at the huge telescope'"
see http://www.imagemagick.org/Usage/text/#draw

Perhaps you should try using -annotate in place of -draw, if this does not work.

Both these commands work fine for me on IM 6.9.4.6 Q16 MacOSX and also 6.8.9.9 (sorry my 6.7.7.10 is too old to work with my current libpng)

Code: Select all

 convert -size 500x500 xc:none -pointsize 20 -font Helvetica -define png:format=png32 \
 -fill snow -stroke black -strokewidth 5 -draw "text 2,22 'look at the huge telescope'" \
 -stroke none -draw "text 2,22 'look at the huge telescope'" tmp1.png
The above is type truecoloralpha

Code: Select all

convert -size 500x500 xc:none -pointsize 50 -font Helvetica -define png:format=png32 \
 -fill snow -stroke black -strokewidth 5 -draw "text 2,54 'hi'" \
 -stroke none -draw "text 2,54 'hi'" tmp2.png
The above is type palettealpha.

I am not sure why the difference. But they both work fine. In convert, I could probably force them both to truecoloralpha by adding PNG32:tmpX.png

Mogrify also works for me on both versions:

Code: Select all

convert -size 500x500 xc:none tmp1.png 
mogrify -pointsize 20 -font Helvetica -define png:format=png32 \
-fill snow -stroke black -strokewidth 5 -draw "text 2,22 'look at the huge telescope'" \
-stroke none -draw "text 2,22 'look at the huge telescope'" tmp1.png

Code: Select all

convert -size 500x500 xc:none tmp2.png
mogrify -pointsize 50 -font Helvetica -define png:format=png32 \
-fill snow -stroke black -strokewidth 5 -draw "text 2,54 'hi'" \
-stroke none -draw "text 2,54 'hi'" tmp2.png
Perhaps you are missing some delegate in your 6.8.9.9 versions. What do you get from both systems from

Code: Select all

convert -version
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Optimization

Post by fmw42 »

Your first result is 8-bit RGBA (so 32-bits). Your second result is 8-bit colormap (possibly without transparency?). What are the types for your two input images? Which IM version processed which image? Perhaps you should post links to your input images so we can test your commands with them or at least their identify -verbose information.
jam@tigger.ws
Posts: 7
Joined: 2016-06-01T22:44:04-07:00
Authentication code: 1151

Re: Optimization

Post by jam@tigger.ws »

First thanks for any help, I really appreciate it.

"First, I would suggest you use convert instead of mogrify if you are processing only one image."
The arguments are used programatically not by the shell so QUOTES are not needed and indeed will not work.
The image is generated whenever the overlay changes.

"Your first result is 8-bit RGBA (so 32-bits). Your second result is 8-bit colormap (possibly without transparency?). What are the types for your two input images? Which IM version processed which image? Perhaps you should post links to your input images so we can test your commands with them or at least their identify -verbose information."

There is no input file. I generate the image. My issue is for "long strings" I get 8 bit RGBA yet the same command for a short string gives a 8 bit colormap image (which is not acceptable to Sensoray Card)

I'll try annotate, but convert is messy - the image is "gravity center" not position x,y and so the line moves as the characters change. Also convert produces 2 files each does not have the name IIRC record11.png is specified but record11(1).png and record11(2).png are produced.

"It works for me" demonstrates my exact problem

[delorian] /home/jam [413]% convert -size 500x500 xc:none tmp1.png
[delorian] /home/jam [414]% mogrify -pointsize 50 -font Helvetica -define png:format=png32 -fill snow -stroke black -strokewidth 5 -draw "text 2,54 'hi'" -stroke none -draw "text 2,54 'hi'" tmp1.png
[delorian] /home/jam [415]% file tmp1.png tmp1.png: PNG image data, 500 x 500, 8-bit colormap, non-interlaced

[delorian] /home/jam [416]% convert -size 500x500 xc:none tmp1.png[delorian] /home/jam [417]% mogrify -pointsize 50 -font Helvetica -define png:format=png32 -fill snow -stroke black -strokewidth 5 -draw "text 2,54 'hi a much longer string'" -stroke none -draw "text 2,54 'hi a much longer string'" tmp1.png

The generated images are here
http://tigger.ws/record10.png
http://tigger.ws/record11.png

Thanks
James
[delorian] /home/jam [418]% file tmp1.png tmp1.png: PNG image data, 500 x 500, 8-bit/color RGBA, non-interlaced

[delorian] /home/jam [421]% convert -version
Version: ImageMagick 6.8.9-9 Q16 x86_64 2016-06-01 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff wmf x xml zlib

But the working version

[dvr] /home/dvr [1079]% convert -version
Version: ImageMagick 6.7.7-10 2014-03-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

No list of delegates! Nothing in the man pages mentions 'delegate'

James
jam@tigger.ws
Posts: 7
Joined: 2016-06-01T22:44:04-07:00
Authentication code: 1151

Re: Optimization

Post by jam@tigger.ws »

Wow that'll teach me to not preview - sorry
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Optimization

Post by fmw42 »

The only way I know to force 32-bit RGBA is to use convert and preface the output by PNG32:result.png. Mogrify is much older and less functional and perhaps -define png:format=png32 was not implemented for your older versions at least not 6.7.7.10. So I do not know how to force 32-bit RGBA truecolor output in mogrify. You would have to re-process each image in convert to force the PNG32:result.png output. So you might as well start with convert even if you have to write a script loop over each image you want to process.

I do not know why you insist that -draw does not need the correct quoting. It won't work without it. So unless your programmatic code accounts for the quotes, I do not see how that works.

In 6.7.7.10, you probably need to do

convert -list configure

to get the list of delegate. I do not see anything obvious with your list of delegates in the newer version.

I would like to see your source images before the convert.

I take it the issue is not that the result is not readable, but that some other software does not handle 8-bit pseudocolor with transparncy for png. Is that correct?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Optimization

Post by fmw42 »

You could try adding -define png:color-type=6, but that did not work for me in mogrify. At http://www.imagemagick.org/Usage/formats/#png_write, I do not see -define png:format= as an option.
jam@tigger.ws
Posts: 7
Joined: 2016-06-01T22:44:04-07:00
Authentication code: 1151

Re: Optimization

Post by jam@tigger.ws »

The 6.7.. version works perfectly (ubuntu 14.04)
The 6.8.. version does not work correctly on short strings (ubuntu 16.04)

Like thee, I have tried the png:color-type=6 and it remains as 3

I do not know why you insist that -draw does not need the correct quoting. To be clear there are shell quotes and program quotes
eg
-draw "text 2,54 'hi'"
The " are shell uotes
The ' are needed by IM. My use of quotes is correct witness by the results, no magic here.

I'll fiddle with convert, but if older mogrify was not changed there would be no issue. The change is what this is all about.

I'll report back what I do with convert, and yes the sensoray card accepts ONLY RGBA 8 bit images
jam@tigger.ws
Posts: 7
Joined: 2016-06-01T22:44:04-07:00
Authentication code: 1151

Re: Optimization

Post by jam@tigger.ws »

Indeed convert does what it is told to do, so many thanks to all
James
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Optimization

Post by fmw42 »

It is possible that was a transient bug in your 6.8.9.9 IM and that later versions were fixed.
Post Reply