rendered paste body
sub _is_wide {
# widescreen 16:9 or 16:10
my ($width, $height) = @_;
return 1 if (($width / 16) * 9) == $height;
return 1 if (($width / 16) * 10) == $height;
return;
}
sub _is_regular {
# 4:3 (800x600) 5:4 (1280x1024)
my ($width, $height) = @_;
return 1 if (($width / 4) * 3) == $height;
return 1 if (($width / 5) * 4) == $height;
return;
}
sub img_size {
my ($width, $height) = @_;
return BM_SIZE_UNKNOWN
unless $width && $height;
my $size = 0x0;
if ($width <= 800 || $height <= 600) {
$size = BM_SIZE_TINY;
}
elsif ($width <= 1024 || $height <= 768) {
$size = BM_SIZE_SMALL;
}
elsif ($width <= 1280 || $height <= 1024) {
$size = BM_SIZE_MEDIUM;
}
elsif ($width <= 1600 || $height <= 1200) {
$size = BM_SIZE_LARGE;
}
elsif ($width > 1600 && $height >= 1200) {
$size = BM_SIZE_HUGE;
}
else { croak "Unable to classify w: $width h: $height"; }
# Additional size attributes
# See http://en.wikipedia.org/wiki/Computer_display_standard
$size |= BM_SIZE_WIDE
if _is_wide($width, $height);
# regular
$size |= BM_SIZE_REGULAR
if _is_regular($width, $height);
#say "$width x $height is regular" if $size & BM_SIZE_REGULAR;
#say "$width x $height is wide" if $size & BM_SIZE_WIDE;
return $size;
}