Image::Magick scale smaller makes file size bigger

Discussion in 'Perl Misc' started by Gary Mayor, Feb 14, 2004.

  1. Gary Mayor

    Gary Mayor Guest

    Hi,
    I know this should be in the modules group but as there seems to be a
    lack of anyone else having this problem I thought i'de better give it
    better coverage.
    The problem is i'm using Image Magick to create thumbnails smaller
    images out of large ones. 99% of the time this works great but there's
    1% where the thumbnail has a bigger file size then the original image
    and that I can't understand. The code i'm using is below and I hope
    someone knows what this might be. I've tried resizing and saving the
    images in gimp and the sizes turn out correct. Also if I compress the
    image the size does decrease but why would a image with no compression
    turn out bigger than the original. I also tried adding the icmp or
    whatever it was to the code but that didn't make any difference. How can
    this be anyone know?

    Thanks

    Gary

    my $imager = Image::Magick->new;
    die unless ref $imager;

    my $status = $imager->Read("$infile");
    print "Read: $status\n" if $status;

    $height = $imager->Get('height');
    $width = $imager->Get('width');

    my $ttwidth = 100;

    my $tbheight=1;
    my $tbwidth=1;
    my $fixed=$ttwidth;
    my $scalefix=1;
    my $scalefactor=$width/$fixed;
    $tbheight=$height/$scalefactor;
    $tbwidth=$fixed;

    $count++;
    $original[$count] = $cfile;
    $status = $imager->Write(filename=>"$dir/$cfile");

    $imager->Scale( width=>$tbwidth, height=>$tbheight );

    $imager->Set(Quality=>$compression);

    $new[$count] = "$outfile";
    $status = $imager->Write(filename=>"$dir/$outfile",compression=>'JPEG');
    Gary Mayor, Feb 14, 2004
    #1
    1. Advertising

  2. Gary Mayor

    gnari Guest

    "Gary Mayor" <> wrote in message
    news:c0lgit$hs5$...
    > Hi,
    > I know this should be in the modules group but as there seems to be a
    > lack of anyone else having this problem I thought i'de better give it
    > better coverage.


    there are a lot of other groups with much greater coverage, where these
    questions are equally off-topic.

    > The problem is i'm using Image Magick to create thumbnails smaller
    > images out of large ones. 99% of the time this works great but there's
    > 1% where the thumbnail has a bigger file size then the original image
    > and that I can't understand.


    that is entirely possible. when making a thumbnail, the sofware might
    be doing a lot of processing to make the smaller image recognizable.
    this may include playing with color depth or dithering. the rsulting
    image may not compress as effectively as the original

    > ... Also if I compress the
    > image the size does decrease but why would a image with no compression
    > turn out bigger than the original.


    i do not know what you are talking about. was the original jpeg with
    0 compression?

    anyways some of the graphics newsgroups might be a better place
    for this kind of questions. (unless, of course, if this only happens
    with Image::Magick , but not the Imagemagick commandline tools)


    gnari
    gnari, Feb 14, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    767
    Filip Larsen
    Apr 10, 2007
  2. Peter Kiederich

    text normal smaller bigger

    Peter Kiederich, Jul 5, 2009, in forum: HTML
    Replies:
    11
    Views:
    676
    Jonathan N. Little
    Jul 7, 2009
  3. Marcus
    Replies:
    25
    Views:
    1,602
    Francesco
    Aug 19, 2009
  4. Yannick Turgeon

    App getting bigger and bigger

    Yannick Turgeon, Oct 13, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    130
    Yannick Turgeon
    Oct 14, 2003
  5. Jack
    Replies:
    2
    Views:
    203
    John W. Krahn
    Jan 25, 2008
Loading...

Share This Page