caption increases canvas size more than it should if text contains multiple lines.
Posted: 2019-02-27T16:00:52-07:00
The following script should return the same difference in canvas height between trimmed and non-trimmed image. I'm generating a sting of words that gets larger and larger so wraps more and more. The height difference should remain constant but I see it getting increasing larger each time the string wraps. I've tried multiple fonts. I'm using Ubuntu 18.04 and its Stock Imagemagick installation.
$ convert -version
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib
$ for a in `seq 0 99` ; do \
convert -size 50x caption:"`awk 'BEGIN {while (c++<'$a') printf "'"test "'"}'`test" -format "%h " -identify -trim -format "%h" -identify dummy.gif \
|awk '{a=$1-$2; printf("%d; ",a);}' ; \
done
7; 7; 9; 9; 11; 11; 13; 13; 15; 15; 17; 17; 19; 19; 21; 21; 23; 23; 25; 25; 27; 27; 29; 29; 31; 31; 33; 33; 35; 35; 37; 37; 39; 39; 41; 41; 43; 43; 45; 45; 47; 47; 49; 49; 51; 51; 53; 53; 55; 55; 57; 57; 59; 59; 61; 61; 63; 63; 65; 65; 67; 67; 69; 69; 71; 71; 73; 73; 75; 75; 77; 77; 79; 79; 81; 81; 83; 83; 85; 85; 87; 87; 89; 89; 91; 91; 93; 93; 95; 95; 97; 97; 99; 99; 101; 101; 103; 103; 105; 105;
The Script essentially runs the following and uses awk to print the difference between the two image canvas heights:
convert -size 50x caption:'test' -format %h -identify -trim -format %h -identify dummy.gif
convert -size 50x caption:'test test' -format %h -identify -trim -format %h -identify dummy.gif
convert -size 50x caption:'test test test' -format %h -identify -trim -format %h -identify dummy.gif
...
$ convert -version
Version: ImageMagick 6.9.7-4 Q16 x86_64 20170114 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC Modules OpenMP
Delegates (built-in): bzlib djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png tiff wmf x xml zlib
$ for a in `seq 0 99` ; do \
convert -size 50x caption:"`awk 'BEGIN {while (c++<'$a') printf "'"test "'"}'`test" -format "%h " -identify -trim -format "%h" -identify dummy.gif \
|awk '{a=$1-$2; printf("%d; ",a);}' ; \
done
7; 7; 9; 9; 11; 11; 13; 13; 15; 15; 17; 17; 19; 19; 21; 21; 23; 23; 25; 25; 27; 27; 29; 29; 31; 31; 33; 33; 35; 35; 37; 37; 39; 39; 41; 41; 43; 43; 45; 45; 47; 47; 49; 49; 51; 51; 53; 53; 55; 55; 57; 57; 59; 59; 61; 61; 63; 63; 65; 65; 67; 67; 69; 69; 71; 71; 73; 73; 75; 75; 77; 77; 79; 79; 81; 81; 83; 83; 85; 85; 87; 87; 89; 89; 91; 91; 93; 93; 95; 95; 97; 97; 99; 99; 101; 101; 103; 103; 105; 105;
The Script essentially runs the following and uses awk to print the difference between the two image canvas heights:
convert -size 50x caption:'test' -format %h -identify -trim -format %h -identify dummy.gif
convert -size 50x caption:'test test' -format %h -identify -trim -format %h -identify dummy.gif
convert -size 50x caption:'test test test' -format %h -identify -trim -format %h -identify dummy.gif
...