How can I generate a text list of image filenames and dimensions on OS X?
April 3, 2009 12:28 PM Subscribe
How can I generate a text list of image filenames and dimensions on OS X?
I have about 150 images and I would like to generate a tidy little text list of these images' filenames and dimensions (in pixels.)
Ultimately this will be uses to populate an XML file for use with an image gallery, if that helps at all.
I'm just trying to avoid having to manually write out each individual width and height.
I'm running Leopard (10.5.6) and have access to Adobe CS4 software, but as far as I can tell this isn't possible with something like Bridge and Googling has failed me.
Any ideas?
I have about 150 images and I would like to generate a tidy little text list of these images' filenames and dimensions (in pixels.)
Ultimately this will be uses to populate an XML file for use with an image gallery, if that helps at all.
I'm just trying to avoid having to manually write out each individual width and height.
I'm running Leopard (10.5.6) and have access to Adobe CS4 software, but as far as I can tell this isn't possible with something like Bridge and Googling has failed me.
Any ideas?
Install ImageMagick, and from a terminal, do
in the folder containing the images.
posted by scruss at 12:42 PM on April 3, 2009
identify *
in the folder containing the images.
posted by scruss at 12:42 PM on April 3, 2009
Mac OS X has the
You could combine
You could run it like this:
which puts a
posted by Blazecock Pileon at 1:01 PM on April 3, 2009
image
command built in to the operating system. Type man image
for more info. You could combine
image
with a Perl script like the following example, to get the image filename, width and height into an XML file:#!/usr/bin/perl -w
use warnings;
use strict;
use Getopt::Long;
use File::Basename;
use IO::File;
use XML::Writer;
my ($inputDir, $outputDir, $imageSuffix);
my $optResults = GetOptions("inputDir=s" => \$inputDir, "outputDir=s" => \$outputDir, "imageSuffix=s" => \$imageSuffix)
# gallery XML options (cf. http://www.airtightinteractive.com/simpleviewer/options.html)
my $maxImageWidth = 960;
my $maxImageHeight = 640;
my $textColor = "0xFFFFFF";
my $frameColor = "0xFFFFFF";
my $frameWidth = "10";
my $stagePadding = "40";
my $navPadding = "40";
my $thumbnailColumns = "3";
my $thumbnailRows = "5";
my $navPosition = "left";
my $vAlign = "center";
my $hAlign = "center";
my $title = "$cellLine";
my $enableRightClickOpen = "true";
my $backgroundImagePath = "";
my $imagePath = "";
my $thumbPath = "";
my $galleryXMLOutput = new IO::File("> $outputDir/gallery.xml");
my $galleryXML = new XML::Writer(OUTPUT => $galleryXMLOutput, NEWLINES => 1, DATA_INDENT => 1);
$galleryXML->xmlDecl('UTF-8');
$galleryXML->startTag('simpleviewergallery', maxImageWidth=>$maxImageWidth, maxImageHeight=>$maxImageHeight, textColor=>$textColor, frameColor=>$frameColor, frameWidth=>$frameWidth, stagePadding=>$stagePadding, navPadding=>$navPadding, thumbnailColumns=>$thumbnailColumns, thumbnailRows=>$thumbnailRows, navPosition=>$navPosition, vAlign=>$vAlign, hAlign=>$hAlign, title=>$title, enableRightClickOpen=>$enableRightClickOpen, backgroundImagePath=>$backgroundImagePath, imagePath=>$imagePath, thumbPath=>$thumbPath);
open (LS, "ls $inputDir/*.$imageSuffix |") or die $?;
while (<LS>) {
chomp;
$_ =~ s/\r//;
my ($filename, undef, undef) = fileparse($_);
my $width = `image width $_`;
my $height = `image height $_`;
$galleryXML->dataElement('filename' => $fileName);
$galleryXML->dataElement('caption' => $_);
$galleryXML->dataElement('width' => $width);
$galleryXML->dataElement('height' => $height);
$galleryXML->endTag('image');
}
close (LS);
$galleryXML->endTag('simpleviewergallery');
$galleryXML->end();
$galleryXMLOutput->close();
# some other system() cmds to copy images, thumbnails and SimpleViewer resources to $outputDir
exit 0;
You could run it like this:
makeGalleryXML.pl --inputDir=sourceImages --outputDir=myGallery --imageSuffix="png"
which puts a
gallery.xml
file in the folder myGallery
, listing PNG files and their attributes in the folder sourceImages
.posted by Blazecock Pileon at 1:01 PM on April 3, 2009
Might want to add:
just before the line:
posted by Blazecock Pileon at 1:03 PM on April 3, 2009
if (! -d $outputDir) { system ("mkdir -p $outputDir") == 0 or die $?; }
just before the line:
my $galleryXMLOutput = new IO::File("> $outputDir/gallery.xml");
posted by Blazecock Pileon at 1:03 PM on April 3, 2009
Actually, scrap
posted by Blazecock Pileon at 1:11 PM on April 3, 2009
image
and just use the Spotlight database or Imagemagick.posted by Blazecock Pileon at 1:11 PM on April 3, 2009
« Older Me fail English? That's unpossible! | Good examples of neighborhood/community websites? Newer »
This thread is closed to new comments.
You'll still need to process that list to get it into exactly the form you want, but the information is there.
posted by hattifattener at 12:38 PM on April 3, 2009 [2 favorites]