Apache-ImageMagick
view release on metacpan or search on metacpan
- Updated the list of allowable attribute to write method call, so
you don't get and unknow attribute error anymore.
- Added AIMCheckMTime which, when set, cause Apache::ImageMagick
to compare the modification time of the source and the cached
image and recompute the result if the source has changed.
- Added AIMDisableSearch to disable auto conversion of image formats
- Directory Requests are ignored now, so they can be handled by Apache
as usual.
- Add example CGI script in scripts/aimcgi.pl
- Start with an test suite. You may run it with perl tst/test.pl but
it may fail on the test which involves fonts, unless you same the
same fonts as on my test machine.
2.0b6 28. Feb 2002
- ImageMagick warnings are only logged, but image is still returned
- Add CGI::ImageMagick which is a fake Apache request and allows
to use Apache::ImageMagick as CGI or offline
- Fix some copy & paste errors, which causes warnings
2.0b5 27. Nov 2001
ImageMagick.pm view on Meta::CPAN
$packnum = 1 ;
$debug = 0 ;
my %LegalArguments = map { $_ => 1 }
qw (antialias adjoin authenticate
background blue-primary bordercolor
cache-threshold colormap colorspace compression
debug delay density depth dispose dither display
endian
filename file fill font fuzz
gravity green-primary
index iterations interlace
loop
magick mattecolor matte monochrome
page pen pixel pointsize preview
quality
red_primary render
sampling-factor scene subimage subrange server size stroke
tile texture type
unit
ImageMagick.pm view on Meta::CPAN
colormap
colorspace
compression
delay
density
dispose
dither
display
file
filename
font
fuzz
green-primary
index
interlace
iterations
loop
magick
matte
mattecolor
monochrome
ImageMagick.pm view on Meta::CPAN
In httpd.conf or .htaccess
<Location /images>
PerlFixupHandler Apache::ImageMagick
PerlSetVar AIMCacheDir /var/aimcache
</Location>
Then request
http://localhost/images/whatever.gif/Annotate?font=Arial&x=5&gravity=west&text=Hello+world+!
http://localhost/images/whatever.jpg
=head1 DESCRIPTION
This module uses the Image::Magick library to process an image on the fly.
It is able to convert the source image to any type you request that is supported
by Image::Magick (e.g. TIFF, PPM, PGM, PPB, GIF, JPEG and more). The requested
fileformat is determinated by the fileextention of the request and
Apache::ImageMagick will search for an image with the same basename and convert it
ImageMagick.pm view on Meta::CPAN
http://localhost/images/whatever.gif/Frame/Shade?Frame:color=gold&Shade:color=true
This will again draw a golden frame and will additonaly add a colored shadow.
The parameters for the C<Set> method a prefixed with C<Set:>
http://localhost/images/whatever.jpg/Frame/Shade?Frame:color=gold&Shade:color=true&Set:quality=10
The C<AIMParameter> configuration diretive can be used to set defaults and/or force
parameters values. So you can say
PerlSetVar AIMParameter "font=/usr/images/fonts/arial.ttf !color=red"
By prefixing the parameter with an !, the parameter values is foreced, so it
can't be overridden by parameters passed to the hanlder via th URI.
=head2 Caching
Since conversion takes time Apache::ImageMagick caches the result unless you turn
off caching with the C<AIMCache> directive. If a cached image is found
Apache::ImageMagick does nothing, but let Apache serve it just like a normal image.
To make cacheing work you normaly have to set the directory where to cache files.
ImageMagick.pm view on Meta::CPAN
memory, Apache::ImageMagick checks if the scripts is modified and if not it is only
executed, so the Perl code has to be compiled only when the script changes.
If C<AIMScriptDir> is not set, Apache::ImageMagick doesn't search for a per image
script. There is a second sort of script the default one. The full path of this script
is specfied by the C<AIMScriptDefault> directive and is executed after the per image
script was executed. So it is able to force some default values.
Both sort of scripts takes four parameters. The Apache request record, the Image::Magick
object of the loaded image, an arrayref which contains the names of all filters and a
hashref that contains all arguments. You can use the Apache object to retrives any
information about the request. You can make any operation on the image object and you
can modify the filters and arguments parameters. Here is an example that forces any fontname
to be searched in a certain directory with the extention ttf. This actualy causes
Image::Magick to use true type fonts:
use constant FONTPATH => '/usr/images/fonts/' ;
use constant FONTDEFAULT => 'arial' ;
my ($r, $image, $filters, $args) = @_ ;
my $font ;
if ($args->{font})
{
$args->{font} =~ m#(^|.*/)([a-zA-z0-9_]+)# ;
$font = $2 ;
}
else
{
$font = FONTDEFAULT ;
}
$args -> {font} = FONTPATH . $font . '.ttf' ;
1 ;
=head2 Createing images from scratch
Instead of modifing an existing image you can also create one from the scratch.
You do this by giving the C<-new=1> parameter. In this case Apache::ImageMagick
will not try to read an exiting image form disk, but create an empty one. You
can use a script to create whatever you like. Here is an example:
ImageMagick.pm view on Meta::CPAN
empty image object along with the other parameters. The scripts creates the
image and Apache::ImageMagick cares about saving the image:
my ($r, $image, $filters, $args) = @_ ;
$image->Set(size=>'30x105');
$image->Read('gradient:#00f685-#0083f8');
$image->Rotate(-90);
$image->Raise('6x6');
$image->Annotate(text=>'Push Me',font=>'/usr/fonts/arial.ttf',fill=>'black',
gravity=>'Center',pointsize=>18);
1 ;
Of course you can run normal filters on such a created image, so you might like to use
a script like this, which creates an empty button, add the annotate filter and sets
some defaults arguments for it:
my ($r, $image, $filters, $args) = @_ ;
$image->Set(size=>'30x105');
$image->Read('gradient:#00f685-#0083f8');
$image->Rotate(-90);
$image->Raise('6x6');
push @$filters, 'Annotate' ;
$args -> {font} = '/usr/fonts/arial.ttf' ;
$args -> {gravity} = 'Center' ;
$args -> {pointsize} = 18 ;
1 ;
And request it with:
http://localhost/images/button.gif?-new=1&text=Push+Me
ImageMagick.pm view on Meta::CPAN
Turn caching off. Default: on.
=item AIMParameter
can be used to set defaults and/or force
parameters values. It contains a space spearated list of parameter values pairs. If you
need spaces inside your values, you have to quote the parameter/value pair.
Example:
PerlSetVar AIMParameter "font=/usr/images/fonts/arial.ttf !color=red"
By prefixing the parameter with an !, the parameter values is foreced, so it
can't be overridden by parameters passed to the hanlder via th URI. If there is no !
then the parameter acts as a default value.
=item AIMDebug
Turn this on to get some debug info into the httpd error log. Default: off.
=item AIMCheckMTime
images/button.gif.pl view on Meta::CPAN
my ($r, $image, $filters, $args) = @_ ;
$image->Set(size=>'30x105');
$image->Read('gradient:#00f685-#0083f8');
$image->Rotate(-90);
$image->Raise('6x6');
$image->Annotate(text=>'Push Me',font=>'/usr/msrc/fonts/arial.ttf',fill=>'black',
gravity=>'Center',pointsize=>18);
1 ;
images/button2.gif.pl view on Meta::CPAN
my ($r, $image, $filters, $args) = @_ ;
$image->Set(size=>'30x105');
$image->Read('gradient:#00f685-#0083f8');
$image->Rotate(-90);
$image->Raise('6x6');
$args -> {font} = '/usr/msrc/fonts/arial.ttf' ;
$args -> {gravity} = 'Center' ;
$args -> {pointsize} = 18 ;
push @$filters, 'Annotate' ;
1 ;
( run in 1.360 second using v1.01-cache-2.11-cpan-ceb78f64989 )