#!/usr/bin/perl -w use strict; $| = 1; use CGI::Carp "fatalsToBrowser"; use CGI ":all"; use GD; # GD library my $tnWidth = 300; # desired thumbnail width my $im = new GD::Image("image.png"); # make thumbnail version my ($w, $h) = $im->getBounds(); my $tnHeight = int($tnWidth * $h / $w); my $out = new GD::Image($tnWidth, $tnHeight); $out->copyResampled($im, 0, 0, 0, 0, $tnWidth, $tnHeight, $w, $h); # thumbnail marked as sample my $black = $im->colorAllocate(0,0,0); $out->string(gdLargeFont,40,40,"Sample",$black); # output thumbnail print header(-type=>'image/png'); binmode STDOUT; print $out->png;