Subject: | Creating mulitple transparent images overlays previous image |
Attached is a small program to create a set of 15 images. My intention
was to create 15 individual transparent images, but what I get is the
first image created correctly, then all subsequent images overlay on top
of each previous image.
It looks like 'my $image = Image::Imlib2->new(20, 100);' does not create
a new image, but refers to a singleton that is reused everytime new() is
called. Even setting the $image variable to undef doesn't clear the
previous image data. Cache is also set to zero.
If this is by design (and looking at the XS code this may well be a
fault with the imlib2 C library), would you be able to add a new method,
e.g. clear(), that removes all previously stored data?
Subject: | imlib.pl |
#!/usr/bin/perl -w
use strict;
use Image::Imlib2;
my @headings = (
'Perl Version',
'MSWin32',
'cygwin',
'darwin',
'dec_osf',
'dragonfly',
'freebsd',
'gnu',
'hpux',
'irix',
'linux',
'mirbsd',
'netbsd',
'openbsd',
'solaris',
);
Image::Imlib2->set_cache_size(0);
for my $text (@headings) {
my $file = $text;
$file =~ s/\s+//g;
# create a new image
my $image = Image::Imlib2->new(20, 100);
$image->add_font_path("/usr/share/fonts/truetype/freefont");
$image->load_font('FreeSans/10');
# Enable the alpha channel support
$image->has_alpha(1);
#$image->set_color(255, 127, 0, 255);
#$image->fill_rectangle(0, 0, 20, 100);
$image->set_color(255, 255, 255, 255);
$image->draw_text(0, 5, $text, TEXT_TO_DOWN, 90);
# save out
$image->save("headings/$file.png");
$image = undef;
}