biotext.org.uk

Tag: perl

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.

3 Comments :, , more...

Simple server status monitoring with PHP and Perl

by Andrew on Feb.17, 2009, under Research

Recently, one of our web servers fell victim to an apparent DoS attack, being hammered with hundreds of simultaneous dynamic page requests, far more than it’s specced to handle. To its credit, it stayed up, although it took about five minutes to log in via ssh, and when we spotted what was happening, the load average was over 100 which I think is the most loaded I’ve ever seen. The offending IP address was at UCSD who do a lot of bioinformatics, so there is a chance it was a misguided attempt to scrape a lot of data from us, rather than an actual hostile act, but in any case the upshot is the same.

It worried me that there was no easy way to remotely check the machine’s health, so I hacked together a quick PHP page to report various vital statistics on demand — load average, memory usage, disk usage etc. — and a Perl monitor that can raise the alarm if anything exceeds safe bounds.

(continue reading…)

3 Comments :, , , more...

Search

Use the form below to search the site:

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