NAME

Image::Embroidery - Parse and display embroidery data files

SYNOPSIS

use Image::Embroidery;

# Constructor
$emb = Image::Embroidery->new();

ABSTRACT

Parse and display embroidery data files

DESCRIPTION

This module can be used to read, write and (with GD) display embroidery data files. It currently only supports Tajima DST files, but if there is any interest it could be expanded to deal with other formats. In its current form it isn't ideal for creating or modifying patterns, but I'm reluctant to put much effort into it until someone tells me they are using it.

EXAMPLES

This is an example of using the module to manipulate a data file and write out the changes.

use Image::Embroidery qw(:all);

$emb = Image::Embroidery->new();

$emb->read_file( '/path/to/embroidery.dst' ) or
   die "Failed to read data file: $!";

# fiddle with the data structure some. this would make
# the 201st entry a normal stitch that went 5 units right,
# and 7 units up
$emb->{'data'}{'pattern'}[200] = [ $NORMAL, 5, 7 ];

# supply a new file name, or use the default of 
# the original file name
$emb->write_file( '/path/to/new_embroidery.dst' ) or
    die "Failed to write data file: $!";

This example demonstrates using GD to create an image file using Image::Embroidery.

use Image::Embroidery;
use GD;

$emb = Image::Embroidery->new();

$emb->read_file( '/path/to/embroidery.dst' ) or
    die "Failed to read data file: $!";

$im = new GD::Image( $emb->size() );

# the first color you allocate will be the background color
$black = $im->colorAllocate(0,0,0);

# the order in which you allocate the rest is irrelevant
$gray = $im->colorAllocate(128,128,128);
$red = $im->colorAllocate(255,0,0);

# the order you specify the colors is the order in which they
# will be used. you must specify the correct number of colors
$emb->draw_logo($im, $gray, $red);

open(IMG, ">", "/path/to/embroidery.png");
print IMG $im->png;
close(F);

METHODS

draw_logo( $gd_image_object, @colors )

Write an image of the stored pattern to the supplied GD::Image object. You must supply the correct number of colors for the pattern. Color arguments are those returned by GD::Image::colorAllocate. Returns 0 on failure, 1 on success.

get_color_changes()

Return the number of colors changes in the pattern. To get the total number of colors in the pattern, add 1 to the value returned by this function.

get_stitch_count()

Return the total number of stitches in the pattern.

get_end_point()

Returns the position of the last point in the pattern, relative to the starting point.

get_abs_size()

Returns the distance from the starting point to the edges of the pattern, in the order +X, -X, +Y, -Y.

read_file( $filename, [ $format ] )

Read an embroidery data file in the specified file format. If the format is omitted, the default is 'tajima'. Returns 0 on failure, 1 on success.

size()

Returns the X and Y size of the pattern.

write_file( [ $filename ], [ $format ] )

Output the contents of the object's pattern to the specified file, using the specified file format. If the filename is omitted, the default filename will be the last file that was successfully read using read_file(). If the format is omitted, the default is 'tajima'. Returns 0 on failure, 1 on success.

FILE FORMATS

Currently, only the Tajima DST file format is supported. It can be specifed to the read_file() and write_file() routines using the string 'tajima', if you feel like being specific.

AUTHOR

Kirk Baucom, <kbaucom@schizoid.com>

COPYRIGHT AND LICENSE

Copyright 2003 by Kirk Baucom

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

2 POD Errors

The following errors were encountered while parsing the POD:

Around line 417:

'=item' outside of any '=over'

Around line 463:

You forgot a '=back' before '=head1'