This program produces a hostname gif, like the one at Aighearach. It uses mod_perl, and Image::Magick. Possibly (probably?) not useful.

Note: I didn't use a PNG because I wanted transparency, and not all browsers support that in a PNG.

#!/usr/bin/perl #-*-PERL-*- use strict; use warnings; use Image::Magick; use Apache; my $image_dir = '/tmp/hostname_images'; my $replace = 0; my $image_type = 'gif'; my $c_foreground = 'black'; my $c_background = 'darkgrey'; my $r = Apache->request(); $r->content_type( "image/$image_type" ); my $remote_host = $r->get_remote_host || $r->connection()->remote_ip() +; my $image = new Image::Magick( ); # We have to create a blank image to work with for Image::Magick::Quer +yFontMetrics() to work $image->Read('xc:white'); my %text = ( text => $remote_host, pointsize => 24, # font => 'Times', gravity => 'Center', fill => $c_foreground, antialias => 'true', ); my @data = $image->QueryFontMetrics( %text ); my ($x_ppem, $y_ppem, $ascender, $descender, $width, $height, $max_adv +ance) = @data; @$image = (); $image->Set( size => "${width}x${height}" ); $image->Read( "xc:${c_background}" ); $image->Annotate( %text ); $image->Transparent( $c_background ); unless ( -d $image_dir ) { mkdir $image_dir or die "failed creating $image_dir: $!"; } my $filename = "$image_dir/$remote_host.$image_type"; unlink( $filename ) if $replace; unless ( -f $filename ) { $image->Write( $filename ); } open( my $file, $filename ) or die "failed opening $filename for reading: $!"; $r->send_http_header; local $/ = undef; $r->print( <$file> ); sub die { $r->content_type( 'text/html' ); $r->print( join( "<br>\n", "error:", @_ ) ); exit; }

In reply to mod_perl hostname gif creator by Aighearach

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.