Apache2-Imager-Resize

 view release on metacpan or  search on metacpan

lib/Apache2/Imager/Resize.pm  view on Meta::CPAN

package Apache2::Imager::Resize;
use strict;

use File::Basename ();
use File::Path ();
use Apache2::Const qw(:common);
use Apache2::RequestUtil;
use Apache2::Request;
use APR::Finfo;
use APR::Const qw(:finfo);
use Imager;
use Data::Dumper;

use vars qw($VERSION);
$VERSION = '0.16';

=head1 NAME

Apache2::Imager::Resize - Fixup handler that resizes and crops images on the fly, caching the results, and doesn't require ImageMagick.

=head1 SYNOPSIS

  <Files "*.jpg">
    PerlFixupHandler  Apache2::Imager::Resize
    PerlSetVar ImgResizeCacheDir '/var/cache/AIRCache/'
  </Files>

  # or

  <Location "/liveimages">
    PerlHandler Apache2::Imager::Resize
    PerlSetVar ImgResizeNoCache on
    PerlSetVar ImgResizeWidthParam 'w'
    PerlSetVar ImgResizeHeightParam 'h'
  </Location>

  # and on a web page somewhere:

  <img src="image.jpg?w=300;h=200;proportional=0" width="300" height="200">

=head1 INTRODUCTION

This is a simple fixup class that only does one job: it resizes images before
they're delivered. All you have to do is append either a width and/or a height
parameter to any image file address, and AIR will make sure that an
appropriately shrunken image file is returned. It caches the results of each
operation, so the first request might take a little while but subsequent
similar requests should be very quick.

This module is based on the code from L<Apache::Imager::Resize>, which does the
same job for Apache 1.x. Some new parameters have been adden, but preexisting
parameters are backwards-compatible.

=head1 PARAMETERS

Apache2::Imager::Resize understands four query string parameters:

=head2 w

width in pixels. You can specify another name with an ImgResizeWidthParam directive.

=head2 h

height in pixels. You can specify another name with an ImgResizeHeightParam directive.

=head2 reshape

If this is 'crop', we will crop without resizing. The default behaviour is
to scale first and then crop to fit the other dimension (see below). If only
one dimension is specified, this parameter has no effect. There will be more
options here in later versions.



( run in 1.898 second using v1.01-cache-2.11-cpan-39bf76dae61 )