Skip to content

Commit

Permalink
Refactored crop
Browse files Browse the repository at this point in the history
  • Loading branch information
kthakore committed May 27, 2011
1 parent 6641563 commit 035d5e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
28 changes: 24 additions & 4 deletions lib/WebGUI/Graphics.pm
Expand Up @@ -142,13 +142,33 @@ sub cropRefactor {

my $image = GD::Image->new($filename) || die "Couldn't read image for resizing: " . $!;

my $crop_img = GD::Image->new( $width, $height );
my $crop_img = GD::Image->new( $width, $height);

$self->session->log->info("Resizing $filename to w:$width h:$height x:$x y:$y");

$crop_img->copy( $image, $x, $y, 0, 0, $width, $height );

my $error = write_gd( $filename, $crop_img->gd );
$crop_img->copy( $image, 0, 0, $x, $y, $width, $height );

my $ext = $self->getFileExtension( $filename );


my $error;
if( $ext =~ 'png')
{
$self->session->log->info("Exporting png croped");
$error = write_gd( $filename, $crop_img->png );
}
elsif( $ext =~ /jpeg|jpg/ )
{
$error = write_gd( $filename, $crop_img->jpeg );
}
elsif( $ext =~ 'gif' )
{
$error = write_gd( $filename, $crop_img->gif );
}
elsif( $ext =~ 'bmp' )
{
$error = write_gd( $filename, $crop_img->wbmp );
}

if ($error) {
$self->session->log->error( "Couldn't resize image: " . $error );
Expand Down
2 changes: 1 addition & 1 deletion lib/WebGUI/Storage.pm
Expand Up @@ -1466,7 +1466,7 @@ sub crop {
=cut

return WebGUI::Graphics::cropRefactor( $self, $self->getPath($filename), $x, $y);
return WebGUI::Graphics::cropRefactor( $self, $self->getPath($filename), $width, $height, $x, $y);

}

Expand Down

0 comments on commit 035d5e4

Please sign in to comment.