#!/icg/bin/perl use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); #) my $file = param ('file'); my $size = param ('size'); my $x = param ('x'); my $y = param ('y'); if ($size =~ /(\d+)x(\d+)/) { ($x, $y) = ($1, $2) } $x = int ($x); $y = int ($y); #figure out image filename $file =~ s{^http://}{}; $file =~ s{^novalis.org}{}; $file =~ s{^/}{}; if ($file =~ /\.\./ || $file =~ /[\\\!\@\#\$\%\^\&\*\"\|\>\<\?]/) { die "Invalid filename {$file}"; } if ($x && $file) { if ($x > 2304 || $y > 2304 || $x < 0 || $y < 0) { #invalid size die "Invalid size $x x $y\n" } if ($file) { $file = "/home/novalis/html/novalis.org/www/$file"; } -e $file || die "No such file"; #don't expand $id = `identify $file`; $id =~ /(\d+)x(\d+)/; if ($x > $1 && $y > $2) { die "I won't expand images"; } my $format; if ($file =~ /jpg$/i) { $format = "jpeg"; } elsif ($file =~ /png$/i || $file =~ /gif$/) { $format = "png"; } $size = "${x}x$y"; print "Content-type:image/$format\n\n"; #spit out the image if (param ('letterbox') eq 'letterbox') { print qx{composite -gravity center -geometry $size -compose Over $file -geometry $size\! xc:black $format:-}; } else { print qx{convert -size $size "$file" -resize $size -}; } } else { print "Content-type:text/html\n\n"; my $img; if ($file) { $img = qq{
}; } print <Image resizer

Resize any image on novalis.org. Just paste the URL below and enter a size. These are maximum dimensions -- that is, the image will be sized such that it can fit in a box of the selected size while maintaining the same ratio of height to width. If you select "letterbox", the generated image will be exactly the dimensions you select, with black filling any unused portions. Images will never be made larger.

Image:
$img Size:
Custom size: x
Letterbox
EOF }