Page 1 of 1

Create new labeled image w/o supplying default size

Posted: 2010-02-02T15:41:45-07:00
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).