Hi,
I decided to use Image::Magick to create thumbnails for images uploaded by an end user.
I'm not sure what I'm missing here, but my purpose of creating a thumbnail is to save bandwidth in the future. I thought it would be logic that if the thumbnail is almost 70% smaller then the original size, then the image size should dramatically be smaller.
Heres a part of my script that uploads an file that was attached via browser and then creates a thumbnail.
if ($chart_name ne "") {
my ($Bytes, $Buffer);
open OUTPUT, ">", $chart_f or die "Can't open: $!";
binmode OUTPUT; #binmode since I'm on Windows
while ($Bytes = read($fh, $Buffer,1024)) {
print OUTPUT $Buffer;
}
close OUTPUT or die "Can't close: $!";
use Image::Magick;
my $image = Image::Magick->new;
my $x = $image->Read($chart_f);
$x = $image->Thumbnail(width=>240, height=>153);
warn "$x" if "$x";
$x = $image->Write($chart_thumb);
warn "$x" if "$x";
}
Everything works for me, the upload and the creation of the thumbnail. However, when checking the file size of the thumbnail, I noticed that it was larger then the original. Can anyone explain to me why this is happening? Only reason I can think of is that Image::Magick adds other features to the image, thus creating it to be larger? I tried resizing an image so that its a thumbnail in Adobe Photoshop, and the filesize of the thumb was significantly lower.
Only other way I can think of is perhaps saving it as a different format other then png using Imagic::Magick? Perhaps a .gif?
Thanks for reading this post.
perleager
429
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.