#!/usr/bin/env perl # # uses ImageMagick's identify command to create a .bb file for an image use warnings; use strict; foreach my $img (@ARGV) { if ( -f $img && -r $img && open( IMG, "identify $img |" ) && open( BB, "> $img.bb" ) ) { while () { my ( $fn, $fmt, @rest ) = split; foreach my $bb (@rest) { if ( $bb =~ /x.*\+/ ) { print STDERR "$fmt image $fn has bounding box $bb\n"; close(IMG); my ( $w, $h, $x, $y ) = split( /[+x]/, $bb ); print BB "%%BoundingBox: $x $y $w $h\r\n"; close(BB); last; } } } } }