Image-BoxModel
view release on metacpan or search on metacpan
make
make test
make install
DEPENDENCIES
This module requires these other modules and libraries:
GD
or
Image::Magick
or
Imager (not implemented yet)
or
all of them if you want to be able to use them all..
COPYRIGHT AND LICENCE
Copyright (C) 2008 by :m)
This library is free software; you can redistribute it and/or modify
lib/Image/BoxModel.pm view on Meta::CPAN
# The preset Colors (see below are read in). This is not done with DATA on purpose.
# I had some strange errors when using Image::BoxModel while open Filehandles in calling programs
%{$image->{preset_colors}} = PresetColors();
#Now follow the definitions of the backend-libraries
#Inheritance is granted by using the appropriate backend-modules.
#This means that if GD is used, then the image-object has ::Backend::GD as its parent, so therefore the appropriate methods in ::Backend::GD are found.
#I don't know if this is good software design..
if ($image -> {lib} eq "IM"){
require Image::Magick;
require Image::BoxModel::Backend::IM;
push @ISA, "Image::BoxModel::Backend::IM";
$image->{IM} = new Image::Magick;
$image->{IM} -> Set(size => ($image->{width}+1)."x".($image->{height}+1)); #IM calculates "human-style" 800x400 is from 0 to 799 and 0 to 399 :-) we do width-- and height-- because we don't do human style in this module.
$image->{IM} -> Read("xc:$image->{background}");
}
elsif ($image -> {lib} eq "GD"){
require GD;
require Image::BoxModel::Backend::GD;
push @ISA, "Image::BoxModel::Backend::GD";
$image->{GD} = new GD::Image($image->{width}+1,$image->{height}+1);
lib/Image/BoxModel.pm view on Meta::CPAN
$image -> Save(file=> "01_hello_world_$image->{lib}.png");
More examples are in examples/
=head1 DESCRIPTION
=head2 OBJECTIVES
Have a way to draw things on images using the same code with different libraries.
Use OO-style design to make the implementation of new library backends (library wrappers) easy. Image::Magick and GD present at the moment.
Use a box model to cut the original image into smaller rectangles. Afterwards objects can be drawn onto these boxes.
=head2 ANOTHER IMAGING / CHARTING / WHATEVER MODULE?
There are many Charting Modules and many Font Modules as well.
There are many concepts about how to layout elements on an image / page.
This module will try hard to make the life of the user easier and the life of the developer more fun.
It has backends for graphic libraries so that you can draw images using the same code with different libraries.
Example: One user (me ;-) starts writing a perl script which produces some charts.
Because Image::Magick is common to me, I use it. After some time I find out that GD would be much faster and is able to do everything I need.
I have to rewrite much of my code because GD does many things different from how IM does them.
..And now someone tells me about the Imager-module from the CPAN!
With this module it is (should be) possible to just replace $image->{lib} in the constructor method and keep the rest of the code.
=head2 PORTABILITY
If you want to write portable code, you have to stick with the following things: (Portability between OSes and between backend libs)
=head3 Don't use fontconfig
You can profit from the wonderful possibilties offered by fontconfig, if you use this module on a system with fontconfig and GD as backend lib.
Anyhow, if you change the backend to Image::Magick later or take your code to a system without fontconfig, it will produce errors.
Perhaps these considerations will lead to removing fontconfig support from Image::BoxModel. Perhaps 'font' will be mandatory for 'Text' and 'Annotate'.
Perhaps there will be a possibilty to specify a default font.
=head3 Copy the font files into your projects directory tree
There is never a guarantee that fonts are present on a different system or on a different machine. You don't know if they are in the same place.
=head3 Always use the 'font' parameter with 'Text' and 'Annotate'
lib/Image/BoxModel.pm view on Meta::CPAN
Yes, of course not. ;-)
It is tempting to use absolute paths to find fonts. Don't. Don't repeat my mistakes. :-)
=head3 Don't use library-methods
It is possible to use every method of the chosen library through the objects library-object:
$image->{IM} -> Edge(radius => "10");
This of course only works with Image::Magick. First, because there will be no {IM} if using GD und second, because GD doesn't know about 'Edge'.
On the other hand, this code will only work with GD:
$image->{GD} -> arc(50,50,95,75,0,360,$image->Colors(color=>'blue'));
There may be cases in which you will want to use library-specific code. Image::BoxModel doesn't implement all features of all libraries. Besides, this would be quite difficult.
=head2 FUTURE
Charts: being done
( run in 0.989 second using v1.01-cache-2.11-cpan-beeb90c9504 )