Steffen Goeldner > Image-Pbm-0.04 > Image::Pbm



Annotate this POD

View/Report Bugs
Module Version: 0.04   Source  


Image::Pbm - Load, create, manipulate and save pbm image files.


  use Image::Pbm();

  my $i = Image::Pbm->new(-width => 50, -height => 25 );
  $i->line     ( 2, 2, 22, 22 => 1 );
  $i->rectangle( 4, 4, 40, 20 => 1 );
  $i->ellipse  ( 6, 6, 30, 15 => 1 );
  $i->xybit    (       42, 22 => 1 );
  print $i->as_string;

  $i = Image::Pbm->new(-file,'test.pbm');


This module provides basic load, manipulate and save functionality for the pbm file format. It inherits from Image::Xbm which provides additional functionality.

See Image::Base and Image::Xbm for a description of all inherited methods.


Imagine, we have to create self-contained web pages (with embedded images). Most browsers understand the xbm image format, but generating xbm files requires a certain effort (or a full fledged graphics software package). On the other hand, generating pbm files is easy. Indeed, it's more likely that you use your favorite text editor instead of Image::Pbm for that task. Reading pbm files is slightly more difficult. That's where the Image::[PX]bm modules come into play:

  use Image::Pbm();


Once we have xbm files, we can serve these images onto the Internet. To embed these images into a web page, we can use the "data" URL scheme:

which requires the standard %xx hex encoding of URLs:

  use URI::Escape();

  my $data = URI::Escape::uri_escape( $xbm );

  print qq(<img src="data:image/x-xbitmap,$data">);

This works with Mozilla and Opera. For Internet Explorer, we can use the following workaround:

  print <<"HTML";
  <pre id="xbm" style="display: none;">$xbm</pre>

    function xbm() { return document.getElementById('xbm').innerHTML; }

  <img src="javascript:xbm()">

This works with Mozilla too.


Contact Mark Summerfield because the inheritance hierarchy

  Image::Pbm <: Image::Xbm <: Image::Base

is suboptimal and should look like

  Image::Xbm <:
                Image::Bitmap <: Image::Base
  Image::Pbm <:


Steffen Goeldner <>


Copyright (c) 2004, 2012 Steffen Goeldner. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


perl, Image::Base, Image::Xbm, Image::PBMlib.

syntax highlighting: