[Xastir] web display
agswilk at gb7lgs.co.uk
agswilk at gb7lgs.co.uk
Tue May 13 17:55:04 EDT 2003
For my Snapshot of Xastir I use a perl script I wrote to add the Date/Time
to the .png from Xastir.
The script (below) requires GD and the Perl GD Module, just run it like:
date_pic.pl /var/tmp/xastir_xwin_snap.png /var/www/xastir.png
------------- Cut ------------
#!/usr/bin/perl
# Change above line to path to your perl binary
# Add's Date/Time Info to Top Left corner of png / jpeg image file.
# by Stewart Wilkinson (G0LGS) 6th August 2002
use GD;
if( $#ARGV >= 1 ) {
$_ = $ARGV[0], /(.*)/;
$source_file = $1;
if( ${source_file} =~ /^.*\.(.*)$/ ) {
$src = $1;
if( ($src !~ /png$/i ) & ( $src !~ /jpg|jpeg$/i) ) {
printf( STDOUT "Unknown / Unsupported Source file format\n");
exit 1;
}
}
$_ = $ARGV[1], /(.*)/;
$dest_file = $1;
if( ${dest_file} =~ /.*\.(.*)$/ ){
$dst = $1;
if( ($dst !~ /png$/) & ( $dst !~ /jpg|jpeg$/ ) ){
printf( STDOUT "Unknown / Unsupported Destination file format\n");
exit 1;
}
}
}else{
printf( STDOUT "Usage: $0 <source> <destination>\n" );
printf( STDOUT "\n\tSource / Destination in jpg|jpeg|png\n" );
exit 1;
}
# Get File Date & Time Information
if( -f ${source_file} ) {
$time = ( stat( _ ) )[10];
}else{
printf( STDOUT "$0: file not found '${source_file}'\n" );
exit 1;
}
($sec,$min,$hour,$mday,$mon,$year,$wday) = gmtime($time);
$Dy = ('00'..'31')[$mday];
$Hr = ('00'..'23')[$hour];
$Mi = ('00'..'59')[$min];
#$Sc = ('00'..'59')[$sec];
$Yr2 = $year + 1900;
$Mn2 = ( 'Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec')[$mon];
#$Mn2 = ( 'January','February','March','April','May','June',
# 'July','August','September','October','November','December')[$mon];
$Dw = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[$wday];
#$Date = "$Dw $Mn2 $Dy $Hr:$Mi:$Sc $Yr2";
$Date = "$Hr:$Mi $Dw $Dy $Mn2 $Yr2";
# Open image
if( ($src =~ /png$/) ){
$im = GD::Image->newFromPng(${source_file});
}else{
$im = GD::Image->newFromJpeg(${source_file});
}
# Allocate some colors
&InitColors($im);
# Use TTF font
$font = "/usr/share/fonts/ttf/western/Bluehigb.ttf";
# Use bounds of Text
if( @bounds = GD::Image->stringFT($red, $font, 18, 0, 15, 30, $Date) ){
($xll,$yll,$xlr,$ylr,$xup,$yur,$xul,$yul) = @bounds;
# Draw Box Filled
$im->filledRectangle($xul-12, $yul-7, $xlr+12, $ylr+7, $gray);
# Draw Border
$im->rectangle($xul-12, $yul-7, $xlr+12, $ylr+7, $black);
$im->rectangle($xul-10, $yul-5, $xlr+10, $ylr+5, $black);
# Draw the Text
$im->stringFT($red, $font, 18, 0, 15, 30, $Date);
}
# Open a file for writing
open(PICTURE, ">${dest_file}") or die("Cannot open file for writing");
# Make sure we are writing to a binary stream
binmode PICTURE;
# Save image as JPEG/PNG and print it to the file PICTURE
if( ($src =~ /png$/) ){
print PICTURE $im->png;
}else{
print PICTURE $im->jpeg;
}
close PICTURE;
exit;
sub InitColors {
my($im) = $_[0];
# Allocate colors
$white = $im->colorAllocate(255,255,255);
$black = $im->colorAllocate(0,0,0);
$gray = $im->colorAllocate(105,105,105);
$gray = $im->colorAllocate(190,190,190);
$red = $im->colorAllocate(255,0,0);
$blue = $im->colorAllocate(0,0,255);
$green = $im->colorAllocate(0, 255, 0);
$brown = $im->colorAllocate(255, 0x99, 0);
$violet = $im->colorAllocate(255, 0, 255);
$yellow = $im->colorAllocate(255, 255, 0);
}
------------- Cut ------------
--
Stewart Wilkinson
agswilk at gb7lgs.co.uk
More information about the Xastir
mailing list