Gisle saves the day. Again.

ziggy on 2005-03-05T18:13:45

I have some scanned images I want to crop and print. Image Capture.app captured them at 300dpi, but all the images are displaying at 72dpi. I want to put all of the cropped images into a single page, and using HTML is reasonable enough. So either I need to scale down the images, or construct tags with the proper width and height.

Like an idiot, the first thing I do is look for a tool to rescale the images. ImageMagick wasn't installed so I installed it. The output from

convert -resize 24% full-size.png scaled.png
looked like utter crap. I haven't had much luck with ImageMagick in the past, so I don't know why I was expecting anything different this time around. port uninstall ImageMagick and on to Plan B.

Poking through /opt/dports/graphics, I didn't see any other obvious candidates for downsampling PNG images.

After I stopped kicking myself for being such an idiot, I did what I should have done the first time:

perl -MCPAN -e 'install Image::Info'
and wrote this script:
#!/opt/bin/perl -w

use strict;
use Image::Info qw(image_info);

foreach (@ARGV) {
        my $image = image_info($_);

        my $w = int($image->{width}*.24);
        my $h = int($image->{height}*.24);

        print qq{

\n}; }

to produce an HTML page with all of the images, properly scaled. Safari does a much better job of rescaling the images, and they come out just fine.

Thanks, Gisle. You've saved the day again.


Image manipulation

Aristotle on 2005-03-05T22:19:49

I recommend NetPBM for anything you'd want to use ImageMagick for.

If you want to put this online, then you should definitely create thumbnails. If it's for local use only, then resizing in the browser is probably better, you avoid the messy extra files.

Re:Image manipulation

ziggy on 2005-03-05T22:52:22

Thanks. I haven't used NetPBM in years. I remember it produced much better quality output than ImageMagick, but I wanted to avoid the PNG -> PNM -> PNG pipeline if at all possible.

Fortunately, these images aren't going online. I was just copying some (paper) documents, so making thumbnails isn't a problem I need to solve today. Otherwise, I'd probably look harder.

Re:Image manipulation

Aristotle on 2005-03-06T01:08:09

Yeah, I found the pipelines a little annoying at first. But then, I remember a lot of occasions of running out of memory with ImageMagick and none with NetPBM; I'd be surprised if ImageMagick internally truly worked incrementally, ie without decompressing the source image fully first, producing compressed output directly. And finally, I've found the “pipe-chain small dedicated tools” approach much easier to figure out than ImageMagick's “364 quadrihoojillion partially order-sensitive switches” commandlines. Not to mention NetPBM is much quicker IME than ImageMagick and produces much better results (it often exceeds GIMP, even).

</gush>