Skip to content

Instantly share code, notes, and snippets.

@potix2
Created December 12, 2011 23:29
Show Gist options
  • Save potix2/1469650 to your computer and use it in GitHub Desktop.
Save potix2/1469650 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -w
use strict;
use warnings;
use constant THRESHOLD => 50;
sub usage {
print "Usage calc_size.pl <width> <height> <original width> <original height>\n";
exit;
}
usage unless ( $#ARGV eq 3 );
my $width = $ARGV[0];
my $height = $ARGV[1];
my $orgWidth = $ARGV[2];
my $orgHeight = $ARGV[3];
my $newHeight;
my $newWidth;
$newWidth = $width;
$newHeight = ($newWidth / 768) * 1024;
if ( $newHeight > $height ) {
$newHeight = $height;
$newWidth = ($newHeight / 1024) * 768;
}
if ( $width - $newWidth > THRESHOLD || $height - $newHeight > THRESHOLD ) {
$newWidth = $width;
$newHeight = $height;
}
my $offsetX = ($orgWidth - $newWidth) / 2;
my $offsetY = 0;
printf("%dx%d+%d+%d\n", $newWidth, $newHeight, $offsetX, $offsetY);
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment