adding twelfth large illustration for 02smr
[project-aon.git] / common / scripts / fix-image-sizes.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 use File::Spec;
6 use Image::Size;
7
8 my $PROG_NAME = 'fix-image-sizes.pl';
9 my $USAGE = "typical usage:\t${PROG_NAME} *.png <input.xml >output.xml\n";
10 die $USAGE if $#ARGV < 0;
11
12 my %image_widths = ( );
13 my %image_heights = ( );
14
15 while( my $file = shift @ARGV ) {
16     my( $volume, $directory, $filename ) = File::Spec->splitpath( $file );
17     ( $image_widths{ $filename }, $image_heights{ $filename } ) = 
18         imgsize( $file );
19 }
20
21 while( my $line = <> ) {
22     if( $line =~ m{<instance.*src="([^"]+)"} ) {
23     my $image = $1;
24         if( exists $image_widths{$image} && defined $image_widths{$image} ) {
25             my $image = $1;
26             if( $line =~ m{width="[^"]*"} ) {
27                 $line =~ s/width="[^"]*"/width="$image_widths{$image}"/;
28             }
29             else {
30                 $line =~ s/(src="[^"]*")/$1 width="$image_widths{$image}"/;
31             }
32
33             if( $line =~ m{height="[^"]*"} ) {
34                 $line =~ s/height="[^"]*"/height="$image_heights{$image}"/;
35             }
36             else {
37                 $line =~ s/(src="[^"]*")/$1 height="$image_heights{$image}"/;
38             }
39         }
40     }
41     print $line;
42 }