biotext.org.uk

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 = &lt;&gt; ) )
{
    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.

Share/save this page:
  • email
  • Print
  • Google Bookmarks
  • del.icio.us
  • Digg
  • Reddit
  • StumbleUpon
  • Technorati
  • DZone
  • Slashdot
  • Fark
  • Facebook
  • MySpace
  • LinkedIn
  • Live
  • connotea
:, ,
3 comments for this entry:
  1. Chad

    Do you know how to look up the resolution of the image in the postscript file?

  2. Andrew

    As far as I understand it, PS files are vector images so don’t really have a resolution. The resolution is dependent on the device you render them on, so a PS file printed on a 600dpi printer will be 600dpi, or on a 120dpi monitor it will be 120dpi.

    Although I think you can embed bitmaps in PS files which will have their own resolution… but they’re a special case.

    I’m not an expert though so I’m happy to be corrected :-)

  3. Chad

    Thanks for the response Andrew. I am trying to analyze postscript made by QuarkXpress and just cant seem to find where they store the resolution of an embedded images. It must be in there somewhere i am just not very familiar with the Postscript language.

    I found BoundingBox that defines the dimentions of the image in points, but not resolution.

    %%Creator: Adobe Photoshop Version 7.0.1
    %%Title: Untitled-1 copy.eps
    %%CreationDate: 10/10/08 10:15 AM
    %%BoundingBox: 0 0 216 216
    %%HiResBoundingBox: 0 0 216 216
    %%SuppressDotGainCompensation
    %%DocumentProcessColors: Cyan Magenta Yellow Black
    %%EndComments
    %%BeginProlog
    %%EndProlog
    %%BeginSetup
    %%EndSetup
    %VectorMaskedImagery
    %ImageData: 900 900 8 4 1 900 1 “beginimage”
    %BeginPhotoshop: 12274

    Anyway, thatks again for the response i will keep reading up on Postscript.

Leave a Reply

Search

Use the form below to search the site:

Leave a comment if you can't find what you need.