Image::Empty - HTTP response helper for 1x1 empty GIFs or PNGs, for building tracking URLs.
Version 0.20
Create 1x1 empty/transparent GIFs or PNGs to use in tracking URLs without the hassle of actually creating and/or loading image data.
Such a basic and common scenario deserves a basic solution.
use Image::Empty; my $gif = Image::Empty->gif; # swap for png print $gif->render; # HTTP headers and body
Returns an instance representing an empty GIF (43 bytes) for use in an HTTP response.
my $gif = Image::Empty->gif;
Returns an instance representing an empty PNG (67 bytes) for use in an HTTP response.
my $png = Image::Empty->png;
The render method is used to set the HTTP headers and body.
render
$gif->render;
With no arguments, returns a string.
Under a CGI environment this would generally be printed directly to STDOUT (ie, the browser).
STDOUT
Chaining methods together can give very concise and compact code.
use Image::Empty; print Image::Empty->gif->render;
Remember that the render method returns the HTTP headers. The above 2 lines are all you need in a script.
If you are working with Plack, supply the Plack::Response object to the render method.
The finalized Plack::Response object is returned.
finalized
As a quick one-liner...
my $app = sub { return Image::Empty->gif->render( Plack::Response->new ); }
It is the same as doing...
my $app = sub { my $gif = Image::Empty->gif; my $response = Plack::Response->new; $response->status(200); $response->content_type( $gif->type ); $response->content_length( $gif->length ); $response->header( 'Content-Disposition' => $gif->disposition . '; filename="' . $gif->filename . '"' ); $response->body( $gif->content ); return $response->finalize; }
If you are working with Catalyst, see Catalyst::View::Image::Empty.
$gif->type;
Returns the mime/type of the image for use in HTTP headers.
$gif->length;
Returns the content length for use in HTTP headers.
$gif->disposition;
Returns the content disposition for use in HTTP headers.
$gif->filename;
Returns the content filename for use in HTTP headers.
$gif->content;
Returns the image data to send in the HTTP response body.
mod_perl support
Rob Brown, <rob at intelcompute.com>
<rob at intelcompute.com>
Please report any bugs or feature requests to bug-image-empty at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Image-Empty. I will be notified, and then you will automatically be notified of progress on your bug as I make changes.
bug-image-empty at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Image::Empty
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Image-Empty
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Image-Empty
CPAN Ratings
http://cpanratings.perl.org/d/Image-Empty
Search CPAN
http://search.cpan.org/dist/Image-Empty/
Copyright 2012 Rob Brown.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
To install Image::Empty, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Image::Empty
CPAN shell
perl -MCPAN -e shell install Image::Empty
For more information on module installation, please visit the detailed CPAN module installation guide.