Tag: graphics
Finding the dimensions of a PostScript image
by Andrew on Sep.08, 2009, under Tips
If I have images in .ps or .eps format, how can I tell how big they are? i.e. how big would they print out at ‘natural’ size without any scaling?
If they have a correct bounding box defined — more likely with EPS than PS files — this bit of Perl will show you the width and height in cm:
#!/usr/bin/env perl use strict; use warnings; # Usage: measure.pl <postscript-file> # Or send it some data on stdin. # Assuming the BBox is correct, it'll tell you the # dimensions in cm. while( defined ( my $line = <> ) ) { if( $line =~ /^%%BoundingBox:\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/ ) { my( $llx, $lly, $urx, $ury ) = ( $1, $2, $3, $4 ); my $x_pts = $urx - $llx; my $y_pts = $ury - $lly; my $x_in = $x_pts / 72; my $y_in = $y_pts / 72; my $x_cm = $x_in * 2.54; my $y_cm = $y_in * 2.54; printf "%.1f %.1f\n", $x_cm, $y_cm; last; } }
Dead handy when preparing images for a paper.
PS if you are hazy about the difference between PS and EPS — like me — have a look at this article.