in reply to Thumbnails and Filehandles

Well, you already have a filehandle from the upload, namely $fh. Just feed that to the Read method.
use strict; use warnings; use Image::Magick; my $image = Image::Magick->new; my $fh = upload('image'); $image->Read(file=>$fh); $image->Thumbnail(geometry=>'150x150'); $image->Write(filename=>'xyz2.jpg');


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Thumbnails and Filehandles
by thekestrel (Friar) on Jul 10, 2005 at 17:54 UTC
    Holli,
    Thanks for the feedback. When I need to then write the data back out (i.e. just send the raw image to a database) how do I get a hold of it, is it possible to use the $image->Write???

    Regards Paul.

    Update: I can't seem to get the method you use of passing the filehandle ($fh) to 'Read' to work. I added a little to the script you made so it should print the raw data to the screen when viewed via a browser...
    #!/usr/bin/perl use strict; use warnings; use Image::Magick; use CGI qw/:standard/; my $cgi = new CGI; my $file = $cgi->param('image'); if ( !$file ) { print header,start_multipart_form(), filefield('image',50,80), submit(-name=>'upload', -value=>'Upload'), end_form(); } else { print header; print "<br>FILE: $file\n"; my $image = Image::Magick->new; my $fh = upload('image'); $image->Read(file=>$fh); my $big_image = $image->ImageToBlob(); print "<br>DATA: $big_image\n"; }