Schedule-TableImage
view release on metacpan or search on metacpan
Makefile.PL view on Meta::CPAN
use ExtUtils::MakeMaker;
# See lib/ExtUtils/MakeMaker.pm for details of how to influence
# the contents of the Makefile that is written.
WriteMakefile(
'NAME' => 'Schedule::TableImage',
'VERSION_FROM' => 'TableImage.pm', # finds $VERSION
'PREREQ_PM' => { Image::Magick => 5.47, Text::Wrapper =>1.000 }, # e.g., Module::Name => 1.1
);
Schedule/TableImage version 1.00
= == == == == == == == == == == == == == == == ==
Schedule::TableImage absolutely relies on Image::Magick being installed on your system.
Schedule::TableImage creates a image of a schedule with labelled events.
This schedule image is a grid in which days are labelled horizontally and hours are labelled vertically.
This is useful to a week view, although you can have as many days as you would like, with any label you like.
Events are colored boxes with text labels for a given time and day.
If events overlap on a given day or time, the width of the day expands to accomodate both (or all) events.
INSTALLATION
To install this module type the following:
perl Makefile.PL
make
make test
make install
DEPENDENCIES
This module requires these other modules and libraries:
Image::Magick
Text::Wrapper
Font files used by Image::Magick (Ghostscript, X server with font specifications, or TrueType fonts)
NOTE ON FONTS:
The demo and test use a postscript format name "Helvetica". This requires that you have the Ghostscript fonts installed on your system in order for the tests to pass. You can use this module without the Ghostscript fonts, but you must then choose ...
If no font is passed in when a new instance of the module is created, this module looks for the truetype font: /usr/local/share/fonts/ttf/arial.ttf. If you do not have this path or this font in your system, be sure to specify the font.
COPYRIGHT AND LICENCE
Copyright (c) 2003 Rebecca A Hunt. All rights reserved.
TableImage.pm view on Meta::CPAN
#---------------------------------------------------------
# Documentation is at the end of the file in POD format.
#-------------------------------------------------------
package Schedule::TableImage;
use strict;
use Image::Magick;
use Text::Wrapper;
require Exporter;
use fields qw(days hours events width height xoffset yoffset totaldays totalhours daywidth hourheight image max_textlen);
use vars qw(%FIELDS $VERSION);
$VERSION = '1.13';
#-----------------------------
# new
TableImage.pm view on Meta::CPAN
#-----------------------------------
# get size values based on font
#------------------------------------
sub _set_text_size {
my ($self) = @_;
my ($x_ppem, $y_ppem, $ascender, $max_advance);
my $text = "12:00 PM";
my $im = Image::Magick->new();
my $rc = $im->Read("label:$text");
$self->error("Error finding text size",
"Could not create image to read text size: $rc") if $rc;
($x_ppem, $y_ppem, $ascender, $self->{pt_txt_desc},$self->{pt_txt_width}, $self->{pt_txt_height}, $max_advance)
= $im->QueryFontMetrics( text=>$text, font=>$self->{font}, pointsize=>$self->{pointsize} );
$self->{txt_width} = int $self->{pt_txt_width} / length($text);
$im ="";
TableImage.pm view on Meta::CPAN
return $num_chars - 1;
}
#--------------------------------------------
# create image reference
#---------------------------------------------
sub _setup_image {
my ($self, $w, $h) = @_;
# some typeing shortcuts
my $im = Image::Magick->new(size => "$w".'x'."$h" );
my ($rc); #errors
$rc = $im->Read('xc:white');
$self->error("Error creating schedule", "Could not create image to write text to: $rc") if $rc;
$self->{image} = $im;
return 1;
}
TableImage.pm view on Meta::CPAN
#------------------------------
1;
__END__
#------------------------------
# POD from here to end of file
#---------------------------------
=head1 NAME
Schedule::TableImage - creates a graphic schedule with labelled events. User inputs the hours, days, and events to show. Uses Image::Magick to generate the image file.
=head1 SYNOPSIS
use Schedule::TableImage;
my $cal = Schedule::TableImage->new(days => \@days, hours => \@hour);
$cal->add_events(\@events);
$cal->write_image($path);
=head1 DESCRIPTION
Creates a image of a schedule with labelled events.
This schedule image is a grid in which days are labelled horizontally and hours are labelled vertically.
This is useful to a week view, although you can have as many days as you would like, with any label you like.
Events are colored boxes with text labels for a given time and day.
If events overlap on a given day or time, the width of the day expands to accomodate both (or all) events.
Requires Image::Magick, and Text::Wrapper.
=head1 FUNCTIONS
=head2 new
Schedule::TableImage->new(days => \@days, hours => \@hour, width=> 450, height=>600, font=>'path/to/font');
Hours is the display name and value is the 4 digit hour code
The hours will be displayed in the order they appear in this array.
TableImage.pm view on Meta::CPAN
day_num => '4',
fill_color => '#CFF66C'
}
);
$cal->add_events(\@events);
=head2 write_image
$cal->write_image('/public_html/myimage.png' [, '90']);
Writes the Image to the given path and filename. You can use any image type your Image::Magick installation supports.
Review the Image::Magick docs to see whether a quality metric is useful to you and your filetype.
=head2 clear_events
clear_events removes all events from your schedule object.
=head2 create_schedule
$cal->create_schedule();
Creates only a blank schedule based on the days and hours.
Does not add the events to the schedule image.
You do not need to call this if you call add_events. Only call this if you want a blank schedule.
=head2 error
$cal->error("one error message", "a different error message");
The current error functionality simply dies with the error messages.
You probably never need to call this, but you may see the effects.
The first error message is something the user might want to see.
The second message has information for the programmer or debugger,
and includes any Image::Magick error messages.
=head1 AUTHOR
Rebecca Hunt (rahunt@mtholyoke.edu)
=head1 BUGS
If the text is too long for an event, the text is not truncated. Instead, it wraps below the bottom line of the event.
=head1 SEE ALSO
( run in 0.416 second using v1.01-cache-2.11-cpan-beeb90c9504 )