Subject: | Not all images are jpegs |
We have a fair amount of pngs we're resizing. Adding the following bit of code to 'sub
generate' preserves the .png extension while defaulting to .jpg, as the old code did:
--- /tmp/x.txt 2009-08-22 16:12:07.000000000 +0000
+++ trunk/perl/5.10/lib/site_perl/5.10.0/Image/Imlib2/Thumbnail.pm 2009-08-22
15:38:54.000000000 +0000
@@ -3,9 +3,10 @@
use warnings;
use Image::Imlib2;
use Path::Class;
+use File::Basename qw(fileparse);
use base qw(Class::Accessor::Fast);
__PACKAGE__->mk_accessors(qw(sizes));
-our $VERSION = '0.34';
+our $VERSION = '0.34_02+HC';
sub new {
my $class = shift;
@@ -80,6 +81,10 @@
my $original_type
= $original_width > $original_height ? 'landscape' : 'portrait';
+ ### not all images are .jpegs. Get the extension from the master
+ ### file and use that on the thumbnails
+ my $ext = [ fileparse( $filename, qr/\.[^.]*?$/ ) ]->[2] || '.jpg';
+
my @thumbnails = (
{ filename => $filename,
name => 'original',
@@ -122,8 +131,8 @@
$width = $scaled_image->width;
}
- my $destination = file( $directory, "$name.jpg" )->stringify;
- $scaled_image->set_quality( $quality );
+ my $destination = file( $directory, "$name$ext" )->stringify;
+ $scaled_image->set_quality( $quality );
$scaled_image->save($destination);
push @thumbnails,
{