Image

Bulk resizing images with Perl

Suppose you’ve just filled you digital camera with an endless stream of photos. You want to place them online at your website, but placing 5+ megapixel files online, well…probably a bad idea. Let’s resize them to a propper size - and why not use Perl and ImageMagick for the job. Not a problem, here’s a complete example on how to resize all images in a directory . Make sure you have ImageMagick installed.

Image sizes in Perl

If you need for figure out the size of an image, fetch Image::Size from CPAN , it’s just what you need. The module recognizes the most common image-formats such as JPG, GIF, PNG, PSD, TIFF and plenty more. The interface is simple and will get you what you need with no trouble at all. #!/usr/bin/perl -w use strict; use Image::Size; # Just fetch the size my ($size_x, $size_y) = Image::Size::imgsize('test.jpg'); print "Image is: $size_y x $size_x (height x width)\n"; # HTML-friendly format my $size = Image::Size::html_imgsize('test.

Image sizes and PHP

If you have the GD extension available, you can do a few useful things. One of the simple things is getting an image size is a simple matter. You can either fetch the height and width in seperate variables – or even fetch the height and width in a string pre-formatted for use in an image tag. Here’s the example in source: $load\_ext = get\_loaded\_extensions(); if (!in\_array(gd, $load\_ext)) { echo "GD is NOT available"; die(); } $nikonFile = '.