DOKK / manpages / debian 10 / pdl / PDL::IO::GD.3pm.en
GD(3pm) User Contributed Perl Documentation GD(3pm)

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

 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");

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.

  Signature: (byte img(x,y); byte lut(i,j); char* filename)

Writes a 2-d PDL variable out to a PNG file, using the supplied color look-up-table piddle (hereafter referred to as a LUT).

The LUT contains a line for each value 0-255 with a corresponding R, G, and B value.

write_png does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

  Signature: (img(x,y); lut(i,j); char* filename; int level)

Same as write_png(), except you can specify the compression level (0-9) as the last argument.

write_png_ex does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

  Signature: (img(x,y,z); char* filename)

Writes an (x, y, z(3)) PDL variable out to a PNG file, using a true color format.

This means a larger file on disk, but can contain more than 256 colors.

write_true_png does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

  Signature: (img(x,y,z); char* filename; int level)

Same as write_true_png(), except you can specify the compression level (0-9) as the last argument.

write_true_png_ex does not process bad values. It will set the bad-value flag of all output piddles if the flag is set for any of the input piddles.

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

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

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

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

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

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

Object Oriented interface to the GD image library.

 # 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" );

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 OO interface is very young, 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.

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

Accepts a hash describing how to create the object. Accepts a single hash ( with curly braces ), an inline hash (the same, but without the braces) or a single string interpreted as a filename. Thus the following are all equivalent:

 PDL::IO::GD->new( {filename => 'image.png'} );
 PDL::IO::GD->new( filename => 'image.png' );
 PDL::IO::GD->new( 'image.png' );

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
 data => $scalar (type => $typename)
    Then a new GD is created from the file data stored in $scalar. 
    If no type is given, then it will try to guess the type of the data, but 
        this will not work for WBMP and gd image types. For those types, you 
        _must_ specify the type of the data, or the operation will fail.
    Valid types are: 'jpg', 'png', 'gif', 'gd', 'gd2', 'wbmp'.

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 });
 
 my $gd = PDL::IO::GD->new({ data => $imageData });
 
 my $gd = PDL::IO::GD->new({ data => $imageData, type => 'wbmp' });

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

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.

$image->write_Png( $filename )

$image->write_PngEx( $filename, $level )

$image->write_WBMP( $fg, $filename )

$image->write_Jpeg( $filename, $quality )

$image->write_Gd( $filename )

$image->write_Gd2( $filename, $cs, $fmt )

$image->write_Gif( $filename )

$image->get_Png_data( )

$image->get_PngEx_data( $level )

$image->get_WBMP_data( $fg )

$image->get_Jpeg_data( $quality )

$image->get_Gd_data( )

$image->get_Gd2_data( $cs, $fmt )

$image->SetPixel( $x, $y, $color )

Alias for gdImageSetPixel.

$image->gdImageSetPixel( $x, $y, $color )

$image->GetPixel( $x, $y )

Alias for gdImageGetPixel.

$image->gdImageGetPixel( $x, $y )

$image->AABlend( )

Alias for gdImageAABlend.

$image->gdImageAABlend( )

$image->Line( $x1, $y1, $x2, $y2, $color )

Alias for gdImageLine.

$image->gdImageLine( $x1, $y1, $x2, $y2, $color )

$image->DashedLine( $x1, $y1, $x2, $y2, $color )

Alias for gdImageDashedLine.

$image->gdImageDashedLine( $x1, $y1, $x2, $y2, $color )

$image->Rectangle( $x1, $y1, $x2, $y2, $color )

Alias for gdImageRectangle.

$image->gdImageRectangle( $x1, $y1, $x2, $y2, $color )

$image->FilledRectangle( $x1, $y1, $x2, $y2, $color )

Alias for gdImageFilledRectangle.

$image->gdImageFilledRectangle( $x1, $y1, $x2, $y2, $color )

$image->SetClip( $x1, $y1, $x2, $y2 )

Alias for gdImageSetClip.

$image->gdImageSetClip( $x1, $y1, $x2, $y2 )

$image->GetClip( $x1P, $y1P, $x2P, $y2P )

Alias for gdImageGetClip.

$image->gdImageGetClip( $x1P, $y1P, $x2P, $y2P )

$image->BoundsSafe( $x, $y )

Alias for gdImageBoundsSafe.

$image->gdImageBoundsSafe( $x, $y )

$image->Char( $f, $x, $y, $c, $color )

Alias for gdImageChar.

$image->gdImageChar( $f, $x, $y, $c, $color )

$image->CharUp( $f, $x, $y, $c, $color )

Alias for gdImageCharUp.

$image->gdImageCharUp( $f, $x, $y, $c, $color )

$image->String( $f, $x, $y, $s, $color )

Alias for gdImageString.

$image->gdImageString( $f, $x, $y, $s, $color )

$image->StringUp( $f, $x, $y, $s, $color )

Alias for gdImageStringUp.

$image->gdImageStringUp( $f, $x, $y, $s, $color )

$image->String16( $f, $x, $y, $s, $color )

Alias for gdImageString16.

$image->gdImageString16( $f, $x, $y, $s, $color )

$image->StringUp16( $f, $x, $y, $s, $color )

Alias for gdImageStringUp16.

$image->gdImageStringUp16( $f, $x, $y, $s, $color )

$image->Polygon( $p, $n, $c )

Alias for gdImagePolygon.

$image->gdImagePolygon( $p, $n, $c )

$image->FilledPolygon( $p, $n, $c )

Alias for gdImageFilledPolygon.

$image->gdImageFilledPolygon( $p, $n, $c )

$image->ColorAllocate( $r, $g, $b )

Alias for gdImageColorAllocate.

$image->gdImageColorAllocate( $r, $g, $b )

$image->ColorAllocateAlpha( $r, $g, $b, $a )

Alias for gdImageColorAllocateAlpha.

$image->gdImageColorAllocateAlpha( $r, $g, $b, $a )

$image->ColorClosest( $r, $g, $b )

Alias for gdImageColorClosest.

$image->gdImageColorClosest( $r, $g, $b )

$image->ColorClosestAlpha( $r, $g, $b, $a )

Alias for gdImageColorClosestAlpha.

$image->gdImageColorClosestAlpha( $r, $g, $b, $a )

$image->ColorClosestHWB( $r, $g, $b )

Alias for gdImageColorClosestHWB.

$image->gdImageColorClosestHWB( $r, $g, $b )

$image->ColorExact( $r, $g, $b )

Alias for gdImageColorExact.

$image->gdImageColorExact( $r, $g, $b )

$image->ColorExactAlpha( $r, $g, $b, $a )

Alias for gdImageColorExactAlpha.

$image->gdImageColorExactAlpha( $r, $g, $b, $a )

$image->ColorResolve( $r, $g, $b )

Alias for gdImageColorResolve.

$image->gdImageColorResolve( $r, $g, $b )

$image->ColorResolveAlpha( $r, $g, $b, $a )

Alias for gdImageColorResolveAlpha.

$image->gdImageColorResolveAlpha( $r, $g, $b, $a )

$image->ColorDeallocate( $color )

Alias for gdImageColorDeallocate.

$image->gdImageColorDeallocate( $color )

$image->TrueColorToPalette( $ditherFlag, $colorsWanted )

Alias for gdImageTrueColorToPalette.

$image->gdImageTrueColorToPalette( $ditherFlag, $colorsWanted )

$image->ColorTransparent( $color )

Alias for gdImageColorTransparent.

$image->gdImageColorTransparent( $color )

$image->FilledArc( $cx, $cy, $w, $h, $s, $e, $color, $style )

Alias for gdImageFilledArc.

$image->gdImageFilledArc( $cx, $cy, $w, $h, $s, $e, $color, $style )

$image->Arc( $cx, $cy, $w, $h, $s, $e, $color )

Alias for gdImageArc.

$image->gdImageArc( $cx, $cy, $w, $h, $s, $e, $color )

$image->FilledEllipse( $cx, $cy, $w, $h, $color )

Alias for gdImageFilledEllipse.

$image->gdImageFilledEllipse( $cx, $cy, $w, $h, $color )

$image->FillToBorder( $x, $y, $border, $color )

Alias for gdImageFillToBorder.

$image->gdImageFillToBorder( $x, $y, $border, $color )

$image->Fill( $x, $y, $color )

Alias for gdImageFill.

$image->gdImageFill( $x, $y, $color )

$image->CopyRotated( $dstX, $dstY, $srcX, $srcY, $srcWidth, $srcHeight, $angle )

Alias for gdImageCopyRotated.

$image->gdImageCopyRotated( $dstX, $dstY, $srcX, $srcY, $srcWidth, $srcHeight, $angle )

$image->SetBrush( )

Alias for gdImageSetBrush.

$image->gdImageSetBrush( )

$image->SetTile( )

Alias for gdImageSetTile.

$image->gdImageSetTile( )

$image->SetAntiAliased( $c )

Alias for gdImageSetAntiAliased.

$image->gdImageSetAntiAliased( $c )

$image->SetAntiAliasedDontBlend( $c, $dont_blend )

Alias for gdImageSetAntiAliasedDontBlend.

$image->gdImageSetAntiAliasedDontBlend( $c, $dont_blend )

$image->SetStyle( $style, $noOfPixels )

Alias for gdImageSetStyle.

$image->gdImageSetStyle( $style, $noOfPixels )

$image->SetThickness( $thickness )

Alias for gdImageSetThickness.

$image->gdImageSetThickness( $thickness )

$image->Interlace( $interlaceArg )

Alias for gdImageInterlace.

$image->gdImageInterlace( $interlaceArg )

$image->AlphaBlending( $alphaBlendingArg )

Alias for gdImageAlphaBlending.

$image->gdImageAlphaBlending( $alphaBlendingArg )

$image->SaveAlpha( $saveAlphaArg )

Alias for gdImageSaveAlpha.

$image->gdImageSaveAlpha( $saveAlphaArg )

$image->TrueColor( )

Alias for gdImageTrueColor.

$image->gdImageTrueColor( )

$image->ColorsTotal( )

Alias for gdImageColorsTotal.

$image->gdImageColorsTotal( )

$image->Red( $c )

Alias for gdImageRed.

$image->gdImageRed( $c )

$image->Green( $c )

Alias for gdImageGreen.

$image->gdImageGreen( $c )

$image->Blue( $c )

Alias for gdImageBlue.

$image->gdImageBlue( $c )

$image->Alpha( $c )

Alias for gdImageAlpha.

$image->gdImageAlpha( $c )

$image->GetTransparent( )

Alias for gdImageGetTransparent.

$image->gdImageGetTransparent( )

$image->GetInterlaced( )

Alias for gdImageGetInterlaced.

$image->gdImageGetInterlaced( )

SX

$image->SX( )

Alias for gdImageSX.

$image->gdImageSX( )

SY

$image->SY( )

Alias for gdImageSY.

$image->gdImageSY( )

$image->ColorAllocates( $r(pdl), $g(pdl), $b(pdl) )

Alias for gdImageColorAllocates.

$image->gdImageColorAllocates( $r(pdl), $g(pdl), $b(pdl) )

$image->ColorAllocateAlphas( $r(pdl), $g(pdl), $b(pdl), $a(pdl) )

Alias for gdImageColorAllocateAlphas.

$image->gdImageColorAllocateAlphas( $r(pdl), $g(pdl), $b(pdl), $a(pdl) )

$image->SetPixels( $x(pdl), $y(pdl), $color(pdl) )

Alias for gdImageSetPixels.

$image->gdImageSetPixels( $x(pdl), $y(pdl), $color(pdl) )

$image->Lines( $x1(pdl), $y1(pdl), $x2(pdl), $y2(pdl), $color(pdl) )

Alias for gdImageLines.

$image->gdImageLines( $x1(pdl), $y1(pdl), $x2(pdl), $y2(pdl), $color(pdl) )

$image->DashedLines( $x1(pdl), $y1(pdl), $x2(pdl), $y2(pdl), $color(pdl) )

Alias for gdImageDashedLines.

$image->gdImageDashedLines( $x1(pdl), $y1(pdl), $x2(pdl), $y2(pdl), $color(pdl) )

$image->Rectangles( $x1(pdl), $y1(pdl), $x2(pdl), $y2(pdl), $color(pdl) )

Alias for gdImageRectangles.

$image->gdImageRectangles( $x1(pdl), $y1(pdl), $x2(pdl), $y2(pdl), $color(pdl) )

$image->FilledRectangles( $x1(pdl), $y1(pdl), $x2(pdl), $y2(pdl), $color(pdl) )

Alias for gdImageFilledRectangles.

$image->gdImageFilledRectangles( $x1(pdl), $y1(pdl), $x2(pdl), $y2(pdl), $color(pdl) )

$image->FilledArcs( $cx(pdl), $cy(pdl), $w(pdl), $h(pdl), $s(pdl), $e(pdl), $color(pdl), $style(pdl) )

Alias for gdImageFilledArcs.

$image->gdImageFilledArcs( $cx(pdl), $cy(pdl), $w(pdl), $h(pdl), $s(pdl), $e(pdl), $color(pdl), $style(pdl) )

$image->Arcs( $cx(pdl), $cy(pdl), $w(pdl), $h(pdl), $s(pdl), $e(pdl), $color(pdl) )

Alias for gdImageArcs.

$image->gdImageArcs( $cx(pdl), $cy(pdl), $w(pdl), $h(pdl), $s(pdl), $e(pdl), $color(pdl) )

$image->FilledEllipses( $cx(pdl), $cy(pdl), $w(pdl), $h(pdl), $color(pdl) )

Alias for gdImageFilledEllipses.

$image->gdImageFilledEllipses( $cx(pdl), $cy(pdl), $w(pdl), $h(pdl), $color(pdl) )

gdImageCopy ( $dst(PDL::IO::GD), $src(PDL::IO::GD), $dstX, $dstY, $srcX, $srcY, $w, $h )

gdImageCopyMerge ( $dst(PDL::IO::GD), $src(PDL::IO::GD), $dstX, $dstY, $srcX, $srcY, $w, $h, $pct )

gdImageCopyMergeGray ( $dst(PDL::IO::GD), $src(PDL::IO::GD), $dstX, $dstY, $srcX, $srcY, $w, $h, $pct )

gdImageCopyResized ( $dst(PDL::IO::GD), $src(PDL::IO::GD), $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH )

gdImageCopyResampled ( $dst(PDL::IO::GD), $src(PDL::IO::GD), $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH )

gdImageCompare ( $im1(PDL::IO::GD), $im2(PDL::IO::GD) )

gdImagePaletteCopy ( $dst(PDL::IO::GD), $src(PDL::IO::GD) )

$image->StringTTF( $brect, $fg, $fontlist, $ptsize, $angle, $x, $y, $string )

Alias for gdImageStringTTF.

$image->gdImageStringTTF( $brect, $fg, $fontlist, $ptsize, $angle, $x, $y, $string )

$image->StringFT( $brect, $fg, $fontlist, $ptsize, $angle, $x, $y, $string )

Alias for gdImageStringFT.

$image->gdImageStringFT( $brect, $fg, $fontlist, $ptsize, $angle, $x, $y, $string )

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

2018-11-02 perl v5.28.0