Reduce file size with Imager

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default Reduce file size with Imager

    Hi, all. I'm using Imager to create gifs, but the resultant
    file sizes are /huge/. I'm writing the files out like so:

    $img->write(type => 'gif',
    max_colors => 16,
    gif_eliminate_unused => 1,
    data => \$data) or die $img->errstr;

    I've verified that the resulting color table /is/ only 16
    colors. Even so, I've opened the resulting files in several
    different graphic editors and saved, and those files are an
    order of magnitude smaller than the ones Imager produces.

    I've tried defining a color map and used several different
    variations on make_colors and translate, but the files still
    seem abnormally large. Is this just a limitation in libgif?
    Any suggestions?

    __________________________________________________ __________
    Eamon Daly




    Eamon Daly Guest

  2. Similar Questions and Discussions

    1. Reduce File Size
      Hi all, I have a couple of very very big pictures, would like to reduce the size down just enough to print out on letter size at a rought quality...
    2. How to Reduce a PDF file size??
      I have a file size 65 MB, the less I can reduce the size is 58 MB using the PDF reduce size option, also I tried using colorsync utility, Quartz...
    3. Reduce file size as a batch
      The reduce file size command doesn't seem to be available in the batch processing list. Does anyone know how to do this?
    4. Reduce File Size Command
      Afraid nor everyone's gone to PDF's. I'd whole lot rather look at a "Dead Tree" manual because I can scan through the book and mark the passages...
    5. CAN I CHANGE SIZE (PIXELS) OF A PROJECTOR TO REDUCE THE FILE SIZE?
      as far as I know you would have to transform bitmap scale all bitmap members to the new size, then readjust their positions to score, and adjust...
  3. #2

    Default Re: Reduce file size with Imager

    Eamon Daly wrote:
    > Hi, all. I'm using Imager to create gifs, but the resultant
    > file sizes are /huge/. I'm writing the files out like so:
    Are you doing animations? If not, skip the GIFs. You can get much
    better depth [16 million] in a lot less space with JPEG files.
    Some of the compression algorithms avaiable are loss-free, too. No
    matter how small the color table, each pixel is still going to take
    its one byte when using GIF. I see that you set a
    gif_eliminate_unused flag, but I am sort of sceptical about how
    effective this will really be. I have never heard of a GIF making
    such optimizations.

    Joseph

    R. Joseph Newton Guest

  4. #3

    Default Re: Reduce file size with Imager

    R. Joseph Newton wrote:
    > Eamon Daly wrote:
    >
    >
    >>Hi, all. I'm using Imager to create gifs, but the resultant
    >>file sizes are /huge/. I'm writing the files out like so:
    >
    >
    > Are you doing animations? If not, skip the GIFs. You can get much
    > better depth [16 million] in a lot less space with JPEG files.
    > Some of the compression algorithms avaiable are loss-free, too. No
    > matter how small the color table, each pixel is still going to take
    > its one byte when using GIF. I see that you set a
    > gif_eliminate_unused flag, but I am sort of sceptical about how
    > effective this will really be. I have never heard of a GIF making
    > such optimizations.
    >
    > Joseph
    >
    I'm sorry, but there are numerous errors here.

    First of all, I know nothing about this Imager package (and indeed, very
    little about Perl), but I suspect the other reply was correct. Check the
    documentation and you will probably find that the package simply does
    not do compression of GIF images. It will write uncompressed GIFs, but
    not compressed ones. The reason is that GIF uses the LZW compression
    algorithm, which is patented in some countries (the patent only recently
    expired in the US), and threats of royalty fees and legal action have
    caused MANY free software packages to stop supporting GIF compression.

    Second, JPEG (actually JFIF) is a very poor replacement for GIF. JPEG
    compression is good for photographs and other realistic images, but not
    for icons, cartoons, and other things that GIF works well for (things
    that have relatively few colors and/or large blocks of the same color).
    When attempting to compress a cartoon, for example, you'll find that
    JPEG/JFIF will give *lower* quality and a *larger* file size than GIF.
    For this type of image, PNG-8 would be a better choice than GIF, and a
    much better choice than JPEG/JFIF.

    Third, only in relatively bad cases will GIF require a byte for every
    pixel. For example, I just created a solid white 200 by 200 image.
    That's 40,000 pixels. The file size is 345 bytes. One byte per pixel is
    what you would get if no compression was used at all (probably what
    happened in this case, but not what happens in general), or if the
    compression performed so badly that it might as well have not been used
    (which is rare for typical images).

    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.


    Kevin Goodsell Guest

  5. #4

    Default Re: Reduce file size with Imager

    Kevin Goodsell wrote:
    > Third, only in relatively bad cases will GIF require a byte for every
    > pixel. For example, I just created a solid white 200 by 200 image.
    > That's 40,000 pixels. The file size is 345 bytes. One byte per pixel is
    > what you would get if no compression was used at all (probably what
    > happened in this case, but not what happens in general), or if the
    > compression performed so badly that it might as well have not been used
    > (which is rare for typical images).
    >
    > -Kevin
    Seriously? I guess I was going by what I have seen in full-color images. I
    may have dismissed the GIF protocol too quickly, when I was doing a lot of
    graphics work. I'll take another look at it. I notice now that I can
    easily raise information on the format through Google, which wasn't really
    the case when I last looked for background on graphics encoding.

    Joseph

    R. Joseph Newton Guest

  6. #5

    Default Re: Reduce file size with Imager

    Kevin Goodsell wrote:
    > Third, only in relatively bad cases will GIF require a byte for every
    > pixel. For example, I just created a solid white 200 by 200 image.
    > That's 40,000 pixels. The file size is 345 bytes. One byte per pixel is
    > what you would get if no compression was used at all (probably what
    > happened in this case, but not what happens in general), or if the
    > compression performed so badly that it might as well have not been used
    > (which is rare for typical images).
    >
    > -Kevin
    Thanks again for the correction. It has spurred some new exploration. I've
    been looking at the published standard on the format, and it is not at all
    like I had assumed. I'm afraid I was lumping it in with BMP and TIFF.
    Anyway, I am starting to untangle the coding:

    Greetings! E:\d_drive\perlStuff>perl -w
    open IN, 'fullhead.gif';
    binmode IN;
    local $/;
    my $img = <IN>;
    my @bytes = split //, $img;
    my $gif_type;
    for (1..6) {
    $gif_type .= shift @bytes;
    }
    print "$gif_type\n";
    my $width = ord(shift @bytes);
    $width += 256 * ord(shift @bytes);
    my $height = ord(shift @bytes);
    $height += 256 * ord(shift @bytes);
    print "Width: $width Height: $height\n";
    my $control_string = ord (shift @bytes);
    my $is_map = $control_string / 128;
    $control_string %= 128;
    my $bit_resolution = int(($control_string / 16) + 1);
    $control_string %= 16;
    $control_string %= 2;
    my $bits_per_pixel = $control_string;
    my $background_color = ord(shift @bytes);
    print "Background is $background_color\n";
    my $color_map = ord(shift @bytes);
    print "Color map is $color_map\n";
    my @colors;
    for (my $i = 0; $i < 2 ** $bit_resolution; $i++) {
    my $color_channels = {};
    $color_channels->{'red'} = ord(shift @bytes);
    $color_channels->{'green'} = ord(shift @bytes);
    $color_channels->{'blue'} = ord(shift @bytes);
    push @colors, $color_channels;
    print 'R: ', sprintf ("%03d", $color_channels->{'red'}),
    ' G: ', sprintf ("%03d", $color_channels->{'green'}),
    ' B: ', sprintf ("%03d", $color_channels->{'blue'}), "\n";
    }

    foreach my $char (@bytes) {
    my $byte = ord($char);
    my $first_nibble = int($byte / 16);
    my $crumbs = $byte % 16;
    print "$first_nibble\n$crumbs\n";
    }
    print 'Data size was ', my $byte_size = @bytes, "\n";

    ^Z
    GIF89a
    Width: 30 Height: 16
    Background is 0
    Color map is 0
    R: 000 G: 000 B: 000
    R: 128 G: 000 B: 000
    ....
    2
    1
    15
    9
    0
    4
    0
    1
    0
    0
    ....
    3
    11
    Data size was 117

    Right now, I'm sort of tracking as I read the spec. I swear to Gawd, I
    couldn't find anything like this last time I went a-hunting!

    It's not very often that you'll see me writing this much flush-left scrit,
    but right now I just want to follow a file through sequentially, and deal
    with each part as it comes.

    Joseph


    R. Joseph Newton Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139