Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I center captions in PerlMagick?
    primarykey
    data
    text
    <p>Using ImageMagick on the command line I can say</p> <pre><code>convert -background '#0000' -fill white -stroke black -strokewidth 3 -gravity center -pointsize 78 -size 568x1000 caption:'Lorem ipsum etc etc' -trim +repage out.png </code></pre> <p>And produce the output I'm looking for. What I'd like to do is the same thing but within PerlMagick so that I don't have to keep reading and writing files as I perform various other steps. Here's what I have so far</p> <pre><code>use strict; use warnings; use Image::Magick; my $im = new Image::Magick; my $e = $im-&gt;Set( background =&gt; '#0000', fill =&gt; 'white', stroke =&gt; 'black', strokewidth =&gt; 3, gravity =&gt; 'center', pointsize =&gt; 78, size =&gt; '586x1000', ); die $e if $e; $e = $im-&gt;Read("caption:Lorem ipsum etc etc"); die $e if $e; $e = $im-&gt;Trim(); die $e if $e; $e = $im-&gt;Set(page=&gt;'0x0+0+0'); # +repage die $e if $e; $e = $im-&gt;Write('out.png'); die $e if $e; </code></pre> <p>And this works precisely the same way, except that the resulting text is not centered.</p> <p>Documentation on PerlMagick is almost nonexistent. I based this "read caption" syntax on some MagicWand examples, where it is claimed that this will result in centered text. Clearly something is different for PerlMagick.</p> <p>So, the question: How can I make PerlMagick respect gravity in this case? How do I get multi-line, centered and word-wrapped text via PerlMagick? Note that this requires that I use caption and not annotate or draw. I'd prefer to avoid manual per-line centering, but I would consider it.</p> <p>Alternatively, if someone has a sample of doing word wrapping and with proportional fonts and Annotate then that would work for me.</p> <p>EDIT: Please note that the -caption option to polaroid, though it shares implementation with what I'm doing, is not the same as the caption: pseudo-image. I would still accept an answer using polaroid and -caption if the output closely matches what is given by the example convert command above.</p> <p>EDIT 2: Here's a more minimal example of the problem.</p> <pre><code>use strict; use warnings; use Image::Magick; my $im = new Image::Magick; my $e = $im-&gt;SetAttribute( background =&gt; '#0000', pointsize=&gt;12, size =&gt; '100x100', gravity =&gt; 'center', ); die $e if $e; $e = $im-&gt;ReadImage('caption:The quick brown fox jumps over the lazy dog.'); die $e if $e; $e = $im-&gt;Write('out.png'); die $e if $e; </code></pre> <p>Expected result: The text is centered.</p> <p>Actual result: The text is left-justified.</p> <p>Actual result should be identical to the output of this command:</p> <pre><code>convert -background '#0000' -size 100x100 -pointsize 12 -gravity center caption:'The quick brown fox jumps over the lazy dog.' out.png </code></pre> <p>From looking at the perlmagick source I see nothing that should be intercepting a particular SetAttribute call, so I don't see why gravity is being ignored. How can I get gravity to not be ignored for this? Or, how else can I do word wrapped and centered text with this kind of output?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload