Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

How to make a thumbnail version of your PNG image

by Baz (Friar)
on Jan 03, 2005 at 18:13 UTC ( [id://419000]=CUFP: print w/replies, xml ) Need Help??

#!/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;

Replies are listed 'Best First'.
Re: How to make a thumbnail version of your PNG image
by b10m (Vicar) on Jan 03, 2005 at 19:25 UTC

    First of all, I don't see the need for use CGI ":all"; for it seems a lot of wasted resources to me ;) If you only going to print the header, I'd suggest not to use CGI.pm at all (print "Content-Type: image/png\n\n";)

    Secondly, besides this code, you could also use: Image::Thumbnail, Image::Magick::Thumbnail, Image::GD::Thumbnail, or even Apache::GD::Thumbnail ... CPAN is your friend here ;)

    --
    b10m

    All code is usually tested, but rarely trusted.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: CUFP [id://419000]
Approved by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 04:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found