Imager::DTP - draw text with DTP app-like custom options |
Imager::DTP - draw text with DTP app-like custom options
use Imager::DTP::Textbox::Horizontal; # or Vertical # first, define font & text string my $font = Imager::Font->new(file=>'path/to/foo.ttf',type=>'ft2', size=>16,color=>'#000000',aa=>1); my $text = "Brother will kill brother, \n"; $text .= "spilling blood across the land.\n"; $text .= "Killing for religion, \n"; $text .= "something I don't understand."; # with multi-byte characters, encode it to UTF8, with internal # utf-8 flag enabled (using utf8::decode()). # create textbox instance my $tb = Imager::DTP::Textbox::Horizontal->new( text=>$text,font=>$font); # draw the text string on target image my $target = Imager->new(xsize=>250,ysize=>250); $target->box(filled=>1,color=>'#FFFFFF'); # with white background $tb->draw(target=>$target,x=>10,y=>10); # and write out image to file $target->write(file=>'result.jpg',type=>'jpeg');
Imager::DTP is a text drawing add-on for Imager, with ability to draw text horizontally or vertically (from top to bottom), letter-based (not word-based) text wrapping for multi-byte characters, line alignment, and adjustment of distance between letters and lines. Vertical drawing and letter-based text wrapping are for multi-byte character languages, such as Japanese and Chinese.
I've made an interactive sample viewer page, for quick and essential understanding of what the output will look like, by using Imager::DTP. You can make the output more complexing and fancy by making full use of the module, but save that for later, and just take a glance at all the basics.
With multi-byte characters, text must be encoded to utf8, with it's internal utf8-flag ENABLED. This could be done by using utf8::decode() method, or with Perl5.8 and above, by using Encode::decode() method.
The main module (the most useful one) of Imager::DTP distribution will be Imager::DTP::Textbox. So see the Imager::DTP::Textbox manpage's documentation for full description on how to use.
Imager::DTP consists of three basic modules (classes). These are:
The class relation of these modules (classes) is as follows:
Imager::DTP::Textbox = [ Imager::DTP::Line = [ Imager::DTP::Letter, Imager::DTP::Letter, Imager::DTP::Letter ... ], Imager::DTP::Line = [ Imager::DTP::Letter, Imager::DTP::Letter, Imager::DTP::Letter ... ], ... ];
So there is no actuall Imager::DTP module (Imager::DTP.pm doesn't exist). The name space is for bundling all these modules under one package name.
Currently, there is one un-solved problem in Imager::DTP::Line, with drawing multi-byte letters vertically. See the Imager::DTP::Line manpage's BUGS section for details.
Please report any bugs or feature requests to bug-imager-dtp@rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
See each basic module's TODO section.
Toshimasa Ishibashi, <iandeth99@ybb.ne.jp>
Copyright 2005 Toshimasa Ishibashi, all rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Imager, the Imager::DTP::Textbox manpage, the Imager::DTP::Line manpage, the Imager::DTP::Letter manpage
Imager::DTP - draw text with DTP app-like custom options |