1 2
sub min($$){ $_[0]<$_[1]?$_[0]:$_[1] } $img->resize(min $gui->width(),$gui->height() / min $img->width(),$img->height());
1 2 3 4 5 6 7 8 9 10 11 12 13 14
sub min($$){ $_[0]<$_[1]?$_[0]:$_[1] } my $gh=$gui->height(); my $gw=$gui->width(); my $ih=$img->height(); my $iw=$img->width(); my $gui_min=min($gw,$gh); my $img_min=min($iw,$ih); my $scale=$gui_min/$img_min; $img->resize($scale);
1 2 3 4 5 6 7 8 9 10 11 12
my $gui_aspect=$gui->width/$gui->height; my $img_aspect=$img->width/$img->heigth; my $diff_aspect=$gui_aspect-$img_aspect; my $scale=1; if($diff_aspect < 0) { $scale=$gui->height/$img->height; } else { $scale=$gui->width/$img->width; } $img->scale($scale);
$img->scale($gui->width / $gui->height - $img->width / $img->heigth < 0? $gui->height / $img->height: $gui->width / $img->width )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
sub min($$){ $_[0]<$_[1]?$_[0]:$_[1] };
my $app_w = 400;
my $app_h = 300;
my $image_w = 200;
my $image_h = 600;
my $y_scale = $app_w / $image_w;
my $x_scale = $app_h / $image_h;
my $factor = min $app_w,$app_h / min $image_w,$image_h;
printf("xs: %s, ys: %s, factor: %s", $x_scale, $y_scale, $factor);
Quotexs: 0.5, ys: 2, factor: 1.5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
my $app_w = 400;
my $app_h = 300;
my $image_w = 600;
my $image_h = 200;
my $y_scale = $app_w / $image_w;
my $x_scale = $app_h / $image_h;
if( $y_scale > $x_scale ) {
print "scale on x axis(scale y < scale x ==> $y_scale < $x_scale)\n";
printf("y-axis overlap: %s\n", int(int($image_h - $app_h) / 2));
}elsif( $y_scale < $x_scale ) {
print "scale on y axis(scale y < scale x ==> $y_scale < $x_scale)\n";
printf("x-axis overlap: %s\n", int(int($image_w - $app_w) / 2));
}else{
print 'doesn\'t matter, it will fit. It has the same aspect ratio as the window.';
}