Christian Soeller > PDL-2.4.3 > PDL::IO::GD

Download:
PDL-2.4.3.tar.gz

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source   Latest Release: PDL-2.007_03

NAME ^

PDL::IO::GD - Interface to the GD image library.

SYNOPSIS ^

 my $pdl = sequence(byte, 30, 30);
 write_png($pdl, load_lut($lutfile), "test.png");

 write_true_png(sequence(100, 100, 3), "test_true.png");

 my $image = read_png("test.png");

 my $image = read_true_png("test_true_read.png");
 write_true_png($image, "test_true_read.out.png");

 my $lut = read_png_lut("test.png");

 $pdl = sequence(byte, 30, 30);
 write_png_ex($pdl, load_lut($lutfile), "test_nocomp.png", 0);
 write_png_ex($pdl, load_lut($lutfile), "test_bestcomp1.png", 9);
 write_png_best($pdl, load_lut($lutfile), "test_bestcomp2.png");

 $pdl = sequence(100, 100, 3);
 write_true_png_ex($pdl, "test_true_nocomp.png", 0);
 write_true_png_ex($pdl, "test_true_bestcomp1.png", 9);
 write_true_png_best($pdl, "test_true_bestcomp2.png");

 recompress_png_best("test_recomp_best.png");

DESCRIPTION ^

This is the "General Interface" for the PDL::IO::GD library, and is actually several years old at this point (read: stable). If you're feeling frisky, try the new OO interface described below.

The general version just provides several image IO utility functions you can use with piddle variables. It's deceptively useful, however.

write_png_best( $img(piddle), $lut(piddle), $filename )

Like write_png(), but it assumes the best PNG compression (9).

write_true_png_best( $img(piddle), $filename )

Like write_true_png(), but it assumes the best PNG compression (9).

recompress_png_best( $filename )

Recompresses the given PNG file using the best compression (9).

load_lut( $filename )

Loads a color look up table from an ASCII file. returns a piddle

read_png( $filename )

Reads a (palette) PNG image into a (new) PDL variable.

read_png_true( $filename )

Reads a true color PNG image into a (new) PDL variable.

my $lut = read_png_lut( $filename )

Reads a color LUT from an already-existing palette PNG file.

OO INTERFACE ^

Object Oriented interface to the GD image library.

SYNOPSIS ^

 # Open an existing file:
 # 
 my $gd = PDL::IO::GD->new( { filename => "test.png" } );
 
 # Query the x and y sizes:
 my $x = $gd->SX();
 my $y = $gd->SY();

 # Grab the PDL of the data:
 my $pdl = $gd->to_pdl();

 # Kill this thing:
 $gd->DESTROY();

 # Create a new object:
 # 
 my $im = PDL::IO::GD->new( { x => 300, y => 300 } );

 # Allocate some colors:
 #
 my $black = $im->ColorAllocate( 0, 0, 0 );
 my $red = $im->ColorAllocate( 255, 0, 0 );
 my $green = $im->ColorAllocate( 0, 255, 0 );
 my $blue = $im->ColorAllocate( 0, 0, 255 );

 # Draw a rectangle:
 $im->Rectangle( 10, 10, 290, 290, $red );

 # Add some text:
 $im->String( gdFontGetLarge(), 20, 20, "Test Large Font!", $green );

 # Write the output file:
 $im->write_Png( "test2.png" );

DESCRIPTION ^

This is the Object-Oriented interface from PDL to the GD image library.

See http://www.boutell.com/gd/ for more information on the GD library and how it works.

IMPLEMENTATION NOTES

Surprisingly enough, this interface has nothing to do with the other Perl->GD interface module, aka 'GD' (as in 'use GD;'). This is done from scratch over the years.

Requires at least version 2.0.22 of the GD library, but it's only been thoroughly tested with gd-2.0.33, so it would be best to use that. The 2.0.22 requirement has to do with a change in GD's font handling functions, so if you don't use those, then don't worry about it.

I should also add, the statement about "thoroughly tested" above is mostly a joke. This is the first version of the OO interface, and it has barely been tested at all, so if something breaks, email me and I'll get it fixed ASAP (for me).

Functions that manipulate and query the image objects generally have a 'gdImage' prefix on the function names (ex: gdImageString()). I've created aliases here for all of those member functions so you don't have to keep typing 'gdImage' in your code, but the long version are in there as well.

FUNCTIONS ^

new

Creates a new PDL::IO::GD object.

Accepts an anonymous hash describing how to create it. Use curly braces here!

If the hash has:

 pdl => $pdl_var (lut => $lut_piddle)
    Then a new GD is created from that PDL variable.

 filename => $file
    Then a new GD is created from the image file.
    
 x => $num, y => $num
    Then a new GD is created as a palette image, with size x, y
    
 x => $num, y => $num, true_color => 1
    Then a new GD is created as a true color image, with size x, y

Example:

 my $gd = PDL::IO::GD->new({ pdl => $pdl_var });
    
 my $gd = PDL::IO::GD->new({ pdl => $pdl_var, lut => $lut_piddle });
 
 my $gd = PDL::IO::GD->new({ filename => "image.png" });
 
 my $gd = PDL::IO::GD->new({ x => 100, y => 100 });
 
 my $gd = PDL::IO::GD->new({ x => 100, y => 100, true_color => 1 });

to_pdl

When you're done playing with your GDImage and want a piddle back, use this function to return one.

apply_lut( $lut(piddle) )

Does a $im->ColorAllocate() for and entire LUT piddle at once.

The LUT piddle format is the same as for the general interface above.

WARNING:

All of the docs below this point are auto-generated (not to mention the actual code), so read with a grain of salt, and always check the main GD documentation about how that function works and what it does.

AUTHOR ^

Judd Taylor, Orbital Systems, Ltd. judd dot t at orbitalsystems dot com

INSERT_NAME_HERE

$image->INSERT_NAME_HERE( INSERT_DOC_ARG_LIST_HERE )

INSERT_NAME_HERE

$image->INSERT_NAME_HERE( INSERT_DOC_ARG_LIST_HERE )

INSERT_SHORT_NAME_HERE

$image->INSERT_SHORT_NAME_HERE( INSERT_DOC_ARG_LIST_HERE )

Alias for INSERT_NAME_HERE.

INSERT_NAME_HERE

$image->INSERT_NAME_HERE( INSERT_DOC_ARG_LIST_HERE )

INSERT_SHORT_NAME_HERE

$image->INSERT_SHORT_NAME_HERE( INSERT_DOC_ARG_LIST_HERE )

Alias for INSERT_NAME_HERE.

CLASS FUNCTIONS ^

INSERT_NAME_HERE

INSERT_NAME_HERE ( INSERT_DOC_ARG_LIST_HERE )

syntax highlighting: