Create new labeled image w/o supplying default size

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
wrs4

Create new labeled image w/o supplying default size

Post by wrs4 »

I want to create a default sized image with some text on a background. If I use
convert -background lightgrey -fill black -font Arial label:test test.png
I get a new image, just large enough to contain the text. I can't seem to replicate that using Image::Magick in Perl. My latest attempt is:

Code: Select all

#!/usr/bin/perl
use strict;

use Image::Magick;

my $dst_file_name = "test.png";
my $res;
my $im = Image::Magick->new;
$res = $im->Set(
                background => "lightgrey",
                fill       => "black",
                font       => "arial.ttf",
               );
die $res if $res;
$im->Label("test");
die $res if $res;
$res = $im->Write($dst_file_name);
die $res if $res;

which dies with the message
Exception 410: no images defined `Image::Magick' at test.pl
I can provide it an existing image as canvas, but that defeats my ability to create a minimally sized image (or, for that matter, to determine the maximum height and width of the text for use elsewhere, which is my ultimage goal).
Post Reply

Who is online

Users browsing this forum: No registered users and 15 guests