in reply to Resizing images with transparent background?
The problem is that Image::Resizer creates a new default image into which it resizes the original. It takes no account of the attributes--truecolor .v. palette; transparancy color etc.--of the original image.
It could (should) query these attributes of the original image and use them to create a compatible image before performing the copyResize(). Something like this (untested) might do the trick:
sub resize { my $self = shift; my ($width, $height, $constraint) = @_; unless ( defined $constraint ) { $constraint = 1; } unless ( $width && $height ) { croak "Image::Resize->resize(): usa +ge error"; } if ( $constraint ) { my $k_h = $height / $self->height; my $k_w = $width / $self->width; my $k = ($k_h < $k_w ? $k_h : $k_w); $height = int($self->height * $k); $width = int($self->width * $k); } my $image = GD::Image->new($width, $height, $self->truecolor ); ## + modified $image->transparent( $self->transparent() ); ## Added $image->copyResampled($self->gd, 0, 0, # (destX, destY) 0, 0, # (srcX, srxY ) $width, $height, # (destX, destY) $self->width, $self->height ); return $image; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Resizing images with transparent background?
by aweizd (Initiate) on Oct 14, 2010 at 12:45 UTC | |
by BrowserUk (Patriarch) on Oct 14, 2010 at 13:05 UTC | |
by aweizd (Initiate) on Oct 14, 2010 at 13:36 UTC | |
by BrowserUk (Patriarch) on Oct 14, 2010 at 14:14 UTC | |
by aweizd (Initiate) on Oct 14, 2010 at 14:50 UTC | |
| |
by Anonymous Monk on Oct 14, 2010 at 13:34 UTC |