NAME
Image::Empty - HTTP response helper for 1x1 empty GIFs or PNGs, for building tracking URLs.
VERSION
Version 0.20
SYNOPSIS
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
$gif
->render;
# HTTP headers and body
METHODS
Class Methods
gif
Returns an instance representing an empty GIF (43 bytes) for use in an HTTP response.
my
$gif
= Image::Empty->gif;
png
Returns an instance representing an empty PNG (67 bytes) for use in an HTTP response.
my
$png
= Image::Empty->png;
Instance Methods
render
The render
method is used to set the HTTP headers and body.
$gif
->render;
With no arguments, returns a string.
Under a CGI environment this would generally be printed directly to STDOUT
(ie, the browser).
Chaining methods together can give very concise and compact code.
use
Image::Empty;
Image::Empty->gif->render;
Remember that the render
method returns the HTTP headers. The above 2 lines are all you need in a script.
Plack
If you are working with Plack, supply the Plack::Response object to the render
method.
The finalized
Plack::Response object is returned.
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;
}
Catalyst
If you are working with Catalyst, see Catalyst::View::Image::Empty.
Attributes
type
$gif
->type;
Returns the mime/type of the image for use in HTTP headers.
length
$gif
->
length
;
Returns the content length for use in HTTP headers.
disposition
$gif
->disposition;
Returns the content disposition for use in HTTP headers.
filename
$gif
->filename;
Returns the content filename for use in HTTP headers.
content
$gif
->content;
Returns the image data to send in the HTTP response body.
TODO
mod_perl support
AUTHOR
Rob Brown, <rob at intelcompute.com>
BUGS
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.
SUPPORT
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)
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
LICENSE AND COPYRIGHT
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.