Hi Monks
I'm making a web-based form whereby a user can upload an image and it will thumbnail it and then add it into a database.
I have the uploading section working and I can send it to the database. I wrote a seperate script to test out Thumbnailing using
Image::Magick and can load a file from the harddrive, thumbnail it and thne write the new image back to disk.
The problem I'm having is putting the two pieces together.
This is the first snippet uses
CGI that does the uploading and puts it in the database;
...
my $fh = upload('image');
if ( !$cover_image && cgi_error ) {
print header(-status=>cgi_error);
}
my $image;
while (<$fh>) {
$image .=$_;
}
my $num = insert_image_db($dbh, $user, $type, $image_title, $image);
...
...and the script that makes the thumbnail...
#!/usr/bin/perl
use strict;
use warnings;
use Image::Magick;
my $image = Image::Magick->new;
open (IMAGE, 'xyz.jpg');
$image->Read(file=>\*IMAGE);
close(IMAGE);
$image->Thumbnail(geometry=>'150x150');
$image->Write(filename=>'xyz2.jpg');
The thing is the Read method for the thumbnailing only takes files or filehandles as inputs and my other script already has the data loaded. I don't want to have to write the image to disk just so I can load it to shrink it.
Is there a easy way of using the data I already have from the upload and make it a filehandle or is there a better was of doing this. I thought that I could open a pipe push the image down it and then I would have a filehandle at the other end to catch it with, but this seems a bit longwinded.
Has anyone come across this before, is there a strightforward method for doing something I'm not familiar with? I appreciate and advice.
Regards Paul
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.