Last active
May 5, 2017 05:21
-
-
Save parserpro/4b677683bbb0ec7a3391cbba390cf6a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use GD; | |
sub resize_img { | |
my ( $img, $x, $y ) = @_; | |
my $jpeg_quality = 60; # Качество картинки на выходе | |
my $max_sizex; | |
my $max_sizey; | |
GD::Image->trueColor(1); # без этого будет жопа | |
my $bildle = GD::Image->new( $img ); | |
my ( $width, $height ) = $bildle->getBounds; | |
$max_sizex = $width / $x; | |
$max_sizey = $height / $y; | |
if ( $max_sizex > $max_sizey ) { | |
$x = $width / $max_sizex; | |
$y = $height / $max_sizex; | |
} else { | |
$x = $width / $max_sizey; | |
$y = $height / $max_sizey; | |
} | |
#create new picture (thumbnail) | |
my $bild=GD::Image->new( $x, $y, 1 ); | |
$bild->copyResampled($bildle,0,0,0,0,$x,$y,$width,$height); | |
$bild->interlaced('true'); # хзчт, надо смотреть доку | |
return $bild->jpeg($jpeg_quality); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment