I'm trying to figure out how to use the Image::Resize
Perl module, to scale down PNG images. The following code does work:
my $image = Image::Resize->new($read_path);
my $gd = $image->resize(1000,1000);
open (DISPLAY,">$write_path") || die "Cant write $write_path, Reason: $!";
binmode DISPLAY;
if ($read_path =~ /\.jpg$/i) {
print DISPLAY $gd->jpeg();
} elsif ($read_path =~ /\.gif$/i) {
print DISPLAY $gd->gif();
} elsif ($read_path =~ /\.png$/i) {
print DISPLAY $gd->png();
}
close DISPLAY;
However, the outcome isn't what I would like (the scaled version has a black background when you convert a transparent PNG)
Scaled:
How can I tell it to put a white background on the image? I checked out the manpage, but couldn't see anything helpful:
http://search.cpan.org/dist/Image-Resize/Resize.pm
Thanks!
UPDATE: For anyone interested, what I ended up doing was just converting them from a .png to .jpg using convert
;
convert "$read_path" -background white -flatten "$path/$filename"
That actually works out better in this instance, as we don't need the transparency (and jpg's are much smaller in size)