You are on page 1of 2

#!/usr/bin/perl -w #******************************** #** name: aspect.

pl #** created: Fri May 31, 2001 #** timestamp: 11:01:09 #******************************** ## If no arguments were given, then allow STDIN to be used only ## if it's not connected to a terminal (otherwise print usage) my ( $viewpane_width, $viewpane_height, $insert_width, $insert_height, $scaling_factor, $proposed_width, $proposed_height, $raw_string, $target_size, ); while(1) { print "---------------------------------------\n"; print "What is the width of the viewpane? "; chomp($viewpane_width = <STDIN>); if(length ($viewpane_width) == 0 || $viewpane_width == 0) { last; } print "What is the height of the viewpane? "; chomp($viewpane_height = <STDIN>); if(length ($viewpane_height) == 0 || $viewpane_height == 0) { last; } print "What is the width of the insert? "; chomp($insert_width = <STDIN>); if(length ($insert_width) == 0 || $insert_width == 0) { last; } print "What is the height of the insert? "; chomp($insert_height = <STDIN>); if(length ($insert_height) == 0 || $insert_height == 0) { last; } $raw_string = "raw:v($viewpane_width x $viewpane_height) i($insert_width x $inse rt_height)"; $raw_string .= sprintf(" w(%f) h(%f)", $insert_width/$viewpane_width, $insert_he ight/$viewpane_height); if($insert_width/$viewpane_width > $insert_height/$viewpane_height) {

$scaling_factor = $viewpane_width / $insert_width; $target_size = sprintf("$insert_width x %d", $viewpane_height/$scaling_f actor); $scaling_factor *= 100.0; } elsif($insert_width/$viewpane_width < $insert_height/$viewpane_height) { $scaling_factor = $viewpane_height / $insert_height; $target_size = sprintf("%d x $insert_height", $viewpane_width/$scaling_f actor); $scaling_factor *= 100.0; } else #($insert_width/$viewpane_width == $insert_height/$viewpane_height) { $target_size = "$insert_width x $insert_height"; $scaling_factor = $viewpane_width / $insert_width; $scaling_factor *= 100.0; } $raw_string .= " s($scaling_factor)"; print "\n\n$raw_string\n\n"; print "Solution\n1. Create a $target_size canvas.\n2. Position the image on the new canvas.\n3. Scale the resulting image by "; printf "%d" , $scaling_factor; print "%\n"; }

You might also like