use TK; use TK::JPEG; sub makeLittlePic { # my $filename = shift; my $newFilename = shift; my $targetSize = shift; my $main = new MainWindow; my $jpgimg = $main -> Photo(-format => 'jpeg', -file => $filename); unless ($jpgimg->height() > $targetSize or $jpgimg->width() > $targetSize) { $jpgimg->write( $newFilename ); return 1; } my $newimg = $main -> Photo('-format' => 'jpeg'); if($jpgimg->height > $jpgimg->width) { $newimg->copy( $jpgimg, -subsample => int($jpgimg->height / $targetSize) ); } else { $newimg->copy( $jpgimg, -subsample => int($jpgimg->width / $targetSize) ); } $newimg->write( $newFilename ); $main = undef; $jpgimg = undef; $newimg = undef; return 1; }