Image-Magick-PolyText

 view release on metacpan or  search on metacpan

Changelog.ini  view on Meta::CPAN

[Module]
Name=Image::Magick::PolyText
Changelog.Creator=Module::Metadata::Changes V 2.11
Changelog.Parser=Config::IniFiles V 2.88

[V 2.00]
Date=2017-01-08T08:36:00
Comments= <<EOT
- Replace /usr/bin/perl with /usr/bin/env perl.
- Replace common::sense with use strict and use warnings, to get uninit var warnings.
- Adopt new repo structure. See
http://savage.net.au/Ron/html/My.Workflow.for.Building.Distros.html.

Changes  view on Meta::CPAN

Revision history for Perl extension Image::Magick::PolyText.

2.00  2017-01-08T08:36:00
	- Replace /usr/bin/perl with /usr/bin/env perl.
	- Replace common::sense with use strict and use warnings, to get uninit var warnings.
	- Adopt new repo structure. See
		http://savage.net.au/Ron/html/My.Workflow.for.Building.Distros.html.
	- Adopt sane version numbering.
	- Switch from Class::Std to Moo.
	- The switch to Moo means params to methods are assumed to be hashes, not hashrefs any more.
		Hence the jump in V from 1.0.3 to 2.00.

META.json  view on Meta::CPAN

      },
      "configure" : {
         "requires" : {
            "ExtUtils::MakeMaker" : "0"
         }
      },
      "runtime" : {
         "requires" : {
            "File::Temp" : "0",
            "Font::FreeType" : "0.07",
            "Image::Magick" : "0",
            "List::Maker" : "0.005",
            "Math::Bezier" : "0.01",
            "Math::Derivative" : "0.04",
            "Math::Interpolate" : "1.06",
            "Moo" : "2.003",
            "POSIX" : "0",
            "Readonly" : "2.05",
            "Time::Elapsed" : "0.32",
            "Types::Standard" : "1.000005",
            "parent" : "0",

META.yml  view on Meta::CPAN

  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: '1.4'
name: Image-Magick-PolyText
no_index:
  directory:
    - t
    - inc
requires:
  File::Temp: '0'
  Font::FreeType: '0.07'
  Image::Magick: '0'
  List::Maker: '0.005'
  Math::Bezier: '0.01'
  Math::Derivative: '0.04'
  Math::Interpolate: '1.06'
  Moo: '2.003'
  POSIX: '0'
  Readonly: '2.05'
  Time::Elapsed: '0.32'
  Types::Standard: '1.000005'
  parent: '0'

Makefile.PL  view on Meta::CPAN

	clean =>
	{
		FILES => 'blib/* Makefile MANIFEST Image-Magick-PolyText-*'
	},
	dist =>
	{
		COMPRESS	=> 'gzip',
		SUFFIX		=> 'gz'
	},
	DISTNAME	=> 'Image-Magick-PolyText',
	NAME		=> 'Image::Magick::PolyText',
	PL_FILES	=> {},
	PREREQ_PM	=>
	{
		'File::Temp'		=> 0,
		'Font::FreeType'	=> 0.07,
		'Image::Magick'		=> undef,
		'List::Maker'		=> 0.005,
		'Math::Bezier'		=> 0.01,
		'Math::Derivative'	=> 0.04,
		'Math::Interpolate'	=> 1.06,
		'Moo'				=> 2.003000,
		'parent'			=> 0,
		'POSIX'				=> 0,
		'Readonly'			=> 2.05,
		'strict'			=> 0,
		'Types::Standard'	=> 1.000005,

README  view on Meta::CPAN

README file for Image::Magick::PolyText.

See also: Changes.txt.

Warning: WinZip 8.1 and 9.0 both contain an 'accidental' bug which stops
them recognizing POSIX-style directory structures in valid tar files.
You are better off using a reliable tool such as InfoZip:
ftp://ftp.info-zip.org/pub/infozip/

1 Installing from a Unix-like distro
------------------------------------

examples/pt.pl  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

use Image::Magick;
use Image::Magick::PolyText;

use Time::Elapsed qw(elapsed);

# ------------------------------------------------

print "Image::Magick::PolyText V $Image::Magick::PolyText::VERSION. \n";
print "\n";

my $start_time	= time;
my $x_1			= [100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700];
my $y_1			= [100, 147, 184, 199, 190, 159, 114, 65, 25, 3, 5, 30, 73];
my $x_2			= [100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700];
my $y_2			= [250, 297, 334, 349, 340, 309, 264, 215, 175, 153, 155, 180, 223]; # $y_1[*] + 150.
my $image		= Image::Magick -> new(size => '800 x 400');
my $result		= $image -> Read('xc:white');
$result			= $image -> Set(font => 't/n019003l.pfb');

die $result if $result;

my $polytext_1 = Image::Magick::PolyText -> new
({
	debug		=> 0,
	fill		=> 'Red',
	image		=> $image,
	pointsize	=> 16,
	rotate		=> 1,
	slide		=> 0.1,
	stroke		=> 'Red',
	strokewidth	=> 1,
	text		=> 'Draw text along a polyline',
	x			=> $x_1,
	y			=> $y_1,
});
my $polytext_2 = Image::Magick::PolyText -> new
({
	debug		=> 0,
	fill		=> 'Red',
	image		=> $image,
	pointsize	=> 16,
	rotate		=> 1,
	slide		=> 0.2,
	stroke		=> 'Red',
	strokewidth	=> 1,
	text		=> 'Draw text along a polyline',

examples/ptf.pl  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

use Image::Magick;
use Image::Magick::PolyText::FreeType;

use Time::Elapsed qw(elapsed);

# ------------------------------------------------

print "Image::Magick::PolyText::FreeType V $Image::Magick::PolyText::FreeType::VERSION. \n";
print "\n";

my $start_time	= time;
my $x_1			= [100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700];
my $y_1			= [100, 147, 184, 199, 190, 159, 114, 65, 25, 3, 5, 30, 73];
my $x_2			= [100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700];
my $y_2			= [250, 297, 334, 349, 340, 309, 264, 215, 175, 153, 155, 180, 223]; # $y_1[*] + 150.
my $image		= Image::Magick -> new(size => '800 x 400');
my $result		= $image -> Read('xc:white');
$result			= $image -> Set(font => 't/n019003l.pfb');

die $result if $result;

my $polytext_1 = Image::Magick::PolyText::FreeType -> new
({
	debug		=> 0,
	fill		=> 'Red',
	image		=> $image,
	pointsize	=> 16,
	rotate		=> 1,
	slide		=> 0.1,
	stroke		=> 'Red',
	strokewidth	=> 1,
	text		=> 'Draw.text.along.a.polyline', # Can't use spaces!
	x			=> $x_1,
	y			=> $y_1,
});
my $polytext_2 = Image::Magick::PolyText -> new
({
	debug		=> 0,
	fill		=> 'Red',
	image		=> $image,
	pointsize	=> 16,
	rotate		=> 1,
	slide		=> 0.2,
	stroke		=> 'Red',
	strokewidth	=> 1,
	text		=> 'Draw.text.along.a.polyline', # Can't use spaces!

examples/test.im.pl  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

use Image::Magick;

use List::Maker;

use Math::Derivative 'Derivative1';

use Readonly;

use Time::Elapsed qw(elapsed);

# ------------------------------------------------

Readonly::Scalar my $pi			=> 3.14159;
Readonly::Scalar my $start_time => time;
my($image)						= Image::Magick -> new(size => '800 x 400');
my($result)						= $image -> Read('xc:white');

die $result if $result;

# Generate the (x, y) pairs
# -------------------------
my(@x, $x);
my($y, @y);

# List::Maker can't handle <0 .. 2 * $pi x 0.1>.

lib/Image/Magick/PolyText.pm  view on Meta::CPAN

package Image::Magick::PolyText;

use strict;
use warnings;

use Math::Bezier;
use Math::Interpolate;

use Moo;

use Readonly;

lib/Image/Magick/PolyText.pm  view on Meta::CPAN

	}

}	# End of highlight_data_points.

# ------------------------------------------------

1;

=head1 NAME

Image::Magick::PolyText - Draw text along a polyline

=head1 Synopsis

	my $polytext = Image::Magick::PolyText -> new
	(
		debug        => 0,
		fill         => 'Red',
		image        => $image,
		pointsize    => 16,
		rotate       => 1,
		slide        => 0.1,
		stroke       => 'Red',
		strokewidth  => 1,
		text         => 'Draw text along a polyline',
		x            => [0, 1, 2, 3, 4],
		y            => [0, 1, 2, 3, 4],
	);

	$polytext -> annotate;

=head1 Description

C<Image::Magick::PolyText> is a pure Perl module.

It is a convenient wrapper around the C<Image::Magick Annotate()> method, for drawing text along a polyline.

=head1 Distributions

This module is available both as a Unix-style distro (*.tgz) and an
ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file.

See http://savage.net.au/Perl-modules.html for details.

See http://savage.net.au/Perl-modules/html/installing-a-module.html for
help on unpacking and installing each type of distro.

=head1 Constructor and initialization

new(...) returns an C<Image::Magick::PolyText> object.

This is the class contructor.

Usage: Image::Magick::PolyText -> new({...}).

This method takes a hashref of parameters.

For each parameter you wish to use, call new as new({param_1 => value_1, ...}).

=over 4

=item o debug

Takes either 0 or 1 as its value.

The default value is 0.

When set to 1, the module writes to STDOUT, and plots various stuff on your image.

This parameter is optional.

=item o fill

Takes an C<Image::Magick> color as its value.

The default value is 'Red'.

The value is passed to the C<Image::Magick Annotate()> method.

This parameter is optional.

=item o image

Takes an C<Image::Magick> object as its value.

There is no default value.

This parameter is mandatory.

=item o pointsize

Takes an integer as its value.

The default value is 16.

The value is passed to the C<Image::Magick Annotate()> method.

This parameter is optional.

=item o rotate

Takes either 0 or 1 as its value.

The default value is 1.

When set to 0, the module does not rotate any characters in the text.

lib/Image/Magick/PolyText.pm  view on Meta::CPAN

Takes a real number in the range 0.0 to 1.0 as its value.

The default value is 0.0.

The value represents how far along the polyline (0.0 = 0%, 1.0 = 100%) to slide the first character of the text.

The parameter is optional.

=item o stroke

Takes an C<Image::Magick> color as its value.

The default value is 'Red'.

The value is passed to the C<Image::Magick Annotate()> method.

This parameter is optional.

=item o strokewidth

Takes an integer as its value.

The default value is 1.

The value is passed to the C<Image::Magick Annotate()> method.

This parameter is optional.

=item o text

Takes a string of characters as its value.

There is no default value.

This text is split character by character, and each character is drawn with a separate call to
the C<Image::Magick Annotate()> method. This is a very slow process. You have been warned.

This parameter is mandatory.

=item o x

Takes an arrayref of x (co-ordinate) values as its value.

There is no default value.

These co-ordinates are the x-axis values of the known points along the polyline.

lib/Image/Magick/PolyText.pm  view on Meta::CPAN

This method writes the text on to your image.

=head2 draw(%options)

%options is an optional hash of (key => value) pairs.

This method draws straight lines from data point to data point.

The default line color is Green.

The options are a hash ref which is passed to the C<Image::Magick Draw()> method, so any option
acceptable to C<Draw()> is acceptable here.

A typical usage would be $polytext -> draw({stroke => 'Blue'});

=head2 highlight_data_points(%options)

%options is an optional hash of (key => value) pairs.

This method draws little (5x5 pixel) rectangles centered on the data points.

The default rectangle color is Red.

The options are a hash ref which is passed to the C<Image::Magick Draw()> method, so any option
acceptable to C<Draw()> is acceptable here.

A typical usage would be $polytext -> highlight_data_points({stroke => 'Black'});

=head1 Example code

See the file examples/pt.pl in the distro.

=head1 Machine-Readable Change Log

lib/Image/Magick/PolyText.pm  view on Meta::CPAN

L<https://github.com/ronsavage/Image-Magick-PolyText>

=head1 Support

Email the author, or log a bug on RT:

L<https://rt.cpan.org/Public/Dist/Display.html?Name=Image-Magick-PolyText>.

=head1 Author

C<Image::Magick::PolyText> was written by Ron Savage I<E<lt>ron@savage.net.auE<gt>> in 2007.

Home page: http://savage.net.au/index.html

=head1 Copyright

Australian copyright (c) 2007, Ron Savage.
	All Programs of mine are 'OSI Certified Open Source Software';
	you can redistribute them and/or modify them under the terms of
	The Perl License, a copy of which is available at:
	http://dev.perl.org/licenses/

lib/Image/Magick/PolyText/FreeType.pm  view on Meta::CPAN

package Image::Magick::PolyText::FreeType;

use parent 'Image::Magick::PolyText';
use strict;
use warnings;

use File::Temp;

use Font::FreeType;

use Image::Magick;

use Moo;

use POSIX 'ceil';

our $VERSION = '2.00';

# ------------------------------------------------
# Constants.

lib/Image/Magick/PolyText/FreeType.pm  view on Meta::CPAN

    "     width='$xmax' height='$ymax'>\n\n" .
    # Transformation to flip it upside down and move it back down into
    # the viewport.
    " <g transform='scale(1 -1) translate(0 -$ymax)'>\n" .
    " <path d='$path'\n" .
    " style='fill: #77FFCC; stroke: #000000'/>\n\n" .
    " </g>\n",
    "</svg>\n";
	close $fh;

	my $bitmap = Image::Magick -> new;
	my $result  = $bitmap -> Read($fh -> filename() );

	die $result if $result;

	# We have to set the background to none so when the bitmap is rotated,
	# the areas filled in where the glyph is moved from are left as white.

	$result = $bitmap -> Set(background => 'None');

	die $result if $result;

lib/Image/Magick/PolyText/FreeType.pm  view on Meta::CPAN

	return $bitmap;

}	# End of glyph2svg2bitmap.

# ------------------------------------------------

1;

=head1 NAME

C<Image::Magick::PolyText::FreeType> - Draw text along a polyline using FreeType and Image::Magick

=head1 Synopsis

	my $polytext = Image::Magick::PolyText::FreeType -> new
	({
		debug        => 0,
		fill         => 'Red',
		image        => $image,
		pointsize    => 16,
		rotate       => 1,
		slide        => 0.1,
		stroke       => 'Red',
		strokewidth  => 1,
		text         => 'Draw.text.along.a.polyline', # Can't use spaces!
		x            => [0, 1, 2, 3, 4],
		y            => [0, 1, 2, 3, 4],
	});

	$polytext -> annotate;

Warning: Experimental code - Do not use.

=head1 Description

C<Image::Magick::PolyText::FreeType> is a pure Perl module.

It is a convenient wrapper around the C<Image::Magick Annotate()> method, for drawing text along a polyline.

Warning: Experimental code - Do not use.

=head1 Distributions

This module is available both as a Unix-style distro (*.tgz) and an
ActiveState-style distro (*.ppd). The latter is shipped in a *.zip file.

See http://savage.net.au/Perl-modules.html for details.

See http://savage.net.au/Perl-modules/html/installing-a-module.html for
help on unpacking and installing each type of distro.

=head1 Constructor and initialization

Warning: Experimental code - Do not use.

new(...) returns an C<Image::Magick::PolyText::FreeType> object.

This is the class contructor.

Usage: Image::Magick::PolyText::FreeType -> new({...}).

This method takes a hashref of parameters.

For each parameter you wish to use, call new as new({param_1 => value_1, ...}).

=over 4

=item o debug

Takes either 0 or 1 as its value.

The default value is 0.

When set to 1, the module writes to STDOUT, and plots various stuff on your image.

This parameter is optional.

=item o fill

Takes an C<Image::Magick> color as its value.

The default value is 'Red'.

The value is passed to the C<Image::Magick Annotate()> method.

This parameter is optional.

=item o image

Takes an C<Image::Magick> object as its value.

There is no default value.

This parameter is mandatory.

=item vpointsize

Takes an integer as its value.

The default value is 16.

The value is passed to the C<Image::Magick Annotate()> method.

This parameter is optional.

=item vrotate

Takes either 0 or 1 as its value.

The default value is 1.

When set to 0, the module does not rotate any characters in the text.

lib/Image/Magick/PolyText/FreeType.pm  view on Meta::CPAN

Takes a real number in the range 0.0 to 1.0 as its value.

The default value is 0.0.

The value represents how far along the polyline (0.0 = 0%, 1.0 = 100%) to slide the first character of the text.

The parameter is optional.

=item o stroke

Takes an C<Image::Magick> color as its value.

The default value is 'Red'.

The value is passed to the C<Image::Magick Annotate()> method.

This parameter is optional.

=item o strokewidth

Takes an integer as its value.

The default value is 1.

The value is passed to the C<Image::Magick Annotate()> method.

This parameter is optional.

=item o text

Takes a string of characters as its value.

There is no default value.

This text is split character by character, and each character is drawn with a separate call to
the C<Image::Magick Annotate()> method. This is a very slow process. You have been warned.

This parameter is mandatory.

=item o x

Takes an array ref of x (co-ordinate) values as its value.

There is no default value.

These co-ordinates are the x-axis values of the polyline.

lib/Image/Magick/PolyText/FreeType.pm  view on Meta::CPAN

This method writes the text on to your image.

=head2 draw(%options)

%options is an optional hash of (key => value) pairs.

This method draws a line through the data points.

The default line color is green.

The options are a hash ref which is passed to the C<Image::Magick Draw()> method, so any option
acceptable to C<Draw()> is acceptable here.

A typical usage would be $polytext -> draw({stroke => 'blue'});

=head2 highlight_data_points(%options)

%options is an optional hash of (key => value) pairs.

This method draws little (5x5 pixel) rectangles centered on the data points.

The default rectangle color is red.

The options are a hash ref which is passed to the C<Image::Magick Draw()> method, so any option
acceptable to C<Draw()> is acceptable here.

A typical usage would be $polytext -> highlight_data_points({stroke => 'black'});

=head1 Example code

See the file examples/ptf.pl in the distro.

=head1 Machine-Readable Change Log

lib/Image/Magick/PolyText/FreeType.pm  view on Meta::CPAN

L<https://github.com/ronsavage/Image-Magick-PolyText>

=head1 Support

Email the author, or log a bug on RT:

L<https://rt.cpan.org/Public/Dist/Display.html?Name=Image-Magick-PolyText>.

=head1 Author

C<Image::Magick::PolyText::FreeType> was written by Ron Savage I<E<lt>ron@savage.net.auE<gt>> in 2007.

Home page: http://savage.net.au/index.html

=head1 Copyright

Australian copyright (c) 2007, Ron Savage.
	All Programs of mine are 'OSI Certified Open Source Software';
	you can redistribute them and/or modify them under the terms of
	The Perl License, a copy of which is available at:
	http://dev.perl.org/licenses/

t/test.t  view on Meta::CPAN

#!/usr/bin/env perl

use strict;
use warnings;

use Test::More;

use Image::Magick;
use Image::Magick::PolyText::FreeType;

# ------------------------------------

my($image)	= Image::Magick -> new(size => '800 x 400');
my($result)	= $image -> Read('xc:white');
$result		= $image -> Set(font => 't/n019003l.pfb');
my($x_1)	= [100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700];
my($y_1)	= [100, 147, 184, 199, 190, 159, 114, 65, 25, 3, 5, 30, 73];
my($x_2)	= [100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700];
my($y_2)	= [250, 297, 334, 349, 340, 309, 264, 215, 175, 153, 155, 180, 223]; # $y_1[*] + 150.
my($writer)	= Image::Magick::PolyText -> new
(
	image	=> $image,
	text	=> 'Draw text along a polyline',
	x		=> $x_1,
	y		=> $y_1,
);

ok(defined $writer);
ok($writer -> isa('Image::Magick::PolyText') );
ok($writer -> image -> isa('Image::Magick') );
ok($writer -> fill eq 'Red');
ok($writer -> pointsize == 16);

$writer -> draw(stroke => 'red');
$writer -> highlight_data_points(stroke => 'black');
$writer -> annotate;

note "Image depth: @{[$image -> get('depth')]} bits per pixel";

done_testing();



( run in 0.899 second using v1.01-cache-2.11-cpan-beeb90c9504 )