Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: shrink.pl - Scales down images

by swilting (Beadle)
on Jan 07, 2009 at 14:33 UTC ( [id://734640]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: shrink.pl - Scales down images
in thread shrink.pl - Scales down images

my cgi shrink image it is necessary to use javascript
#!/usr/bin/perl -wT use strict; use Image::Magick; use CGI qw(:standard escapeHTML); use CGI::Carp qw(fatalsToBrowser); # Declares defaults my ( $dir,$file,$img) = ('/home/renelacroute/imagepublic',"",""); my $q = new CGI; my $r = param("r"); my $hauteur = param("hauteur"); my $largueur = param("largeur"); $file = random_file ($dir, '\\.(png|PNG||jpg|JPG|jpeg|JPEG|gif)$' ); print $q->header( -type => "image/png", -expires => "-1d" ); binmode STDOUT; $img = &shrink($file,$hauteur,$largueur); sub random_file { my( $dir,$mask ) = @_; my $i = 0; my ($file); local( *DIR); opendir DIR, $dir or die "Cannot open $dir: $!"; while ( defined ( $_ = readdir DIR ) ) { /$mask/o or next if defined $mask; rand ++$i < 1 and $file = $_; } closedir DIR; return "$dir/$file"; } # Load the given image ans shrinks it to be within the given size # or percentage sub shrink () { my($name,$hauteur,$largueur) = @_; my($img) = new Image::Magick; print "i got to $name!\n"; ## print $size; my $x = $img->Read($name); warn "$x" if $x; my $y = $img->Resize('width' => $hauteur , 'height' => $largueur ) +; warn "$y" if $y; my $z = $img->Write('png:-'); warn "$z" if $z; undef $img; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2024-04-19 12:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found