Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

runrig (3385)


Just another perl hacker somewhere near Disneyland

I have this homenode [] of little consequence on Perl Monks [] that you probably have no interest in whatsoever.

I also have some modules [] on CPAN [] some of which are marginally [] more [] useful [] than others.

Journal of runrig (3385)

Saturday September 30, 2006
04:02 PM


[ #31176 ]

I've written before about my obsession with Highway 395, but this time I have photos, many of which were taken out the car window (w/my wife's camera...someday I'll get my own), though one of my favorites was taken from inside the car, and one was actually from Lake Tahoe, but I included in the set anyway just because it was so awesome :-)

I did find that the pictures coming out of the camera were at 2560x1920, and since I have the free flickr account, there is a limit on how many MB you can upload. Earlier, I had quickly used up the limit on my wife's account uploading full-size pictures, only to find that they get scaled to 1280x960 when you view the largest version of the image after it's uploaded, but you get "charged" for the actual uploaded size. So this time, I installed Image::Magick, found the documentation, and spent 5 minutes reading it to come up with this:

use Image::Magick;
my @files = <*.jpg>;

for my $file (@files) {
  my $img = Image::Magick->new;
  $img->Scale(width=>1280, height=>960);
  # Yes, I'm overwriting the file, but the whole
  # directory is a copy

I'm sure there must be other ways to do this, but this is what I came up with first, and it worked just fine, though I'd love to hear about alternatives, or anything wrong with the above :-)

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • It always amazes me if people post a multiline program in Perl, when it can be done with a shell one-liner.

    I would do:

    find . -name '*.jpg' -exec convert -resize '1280x960>' {} {} \;
    Shell rules.
    • It always amazes me that people use ImageMagick. :-) What does the greater-than in your size specification mean? Why does ImageMagick have to have such an arcane interface that it shines through even in such a simple example? When I try to do multiple operations, I am always bamboozled by the precedence of the various options. Would that at least the image quality made it all worthwhile… but other tools usually do a much better job.

      NetPBM usually loses out on brevity vs. ImageMagick, but pipes are

      • The greater than sign says: scale only if the image is larger (it prevents a picture to be enlarged). Which is, IMO, a very useful feature. A feature that I haven't seen in NetPBM. (It might be there, but the manual page of pnmscale doesn't mention it).
        • Yeah, you’re right, pnmscale doesn’t have that. You can code around it using pnmfile and explicit checks, but it’s awkward to say the least. Adding -enlargeonly and -reduceonly switches should be easy… (Another advantage of the small-tools philosophy: they all have short and mostly simple sources.) Maybe I’ll submit a patch.

    • It always amazes me if people post a multiline program in Perl, when it can be done with a shell one-liner.

      I normally don't do that, but in this case, I was not aware of the command line tools (I've heard of ImageMagick for years now, but have only just now actually used it), and I only installed the PerlMagick package (on Windows w/ppm). If I do install the whole ImageMagick package, I'll have to do something about that 'convert' command, as there is already a 'convert' on Windows, which does something

  • I hate ImageMagick. It’s slow and its algorithms often produce low-quality results. I don’t like trotting out Perl for small tasks involving fiddling with a lot of files either, the command line interface of ImageMagick is execrable. I use ImageMagick only when I am desperate.

    So I recommend NetPBM [] instead, which consists of a big bag of little programs that you connect together using pipes – a highly intuitive metaphor for image manipulation, I find. A shell script using NetPBM for yo