LibGd 2.4.0-dev
GD Graphics library
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions

PNG image reading and writing support. More...

Collaboration diagram for PNG:

Data Structures

struct  gdPngWriteOptions
 Options for writing PNG data. More...
 
struct  gdPngInfo
 Basic information read from a PNG stream. More...
 

Macros

#define GD_PNG_FILTER_AUTO   0U
 
#define GD_PNG_FILTER_NONE   (1U << 0)
 
#define GD_PNG_FILTER_SUB   (1U << 1)
 
#define GD_PNG_FILTER_UP   (1U << 2)
 
#define GD_PNG_FILTER_AVERAGE   (1U << 3)
 
#define GD_PNG_FILTER_PAETH   (1U << 4)
 
#define GD_PNG_FILTER_ALL
 

Enumerations

enum  {
  GD_PNG_COMPRESSION_STRATEGY_DEFAULT = 0 , GD_PNG_COMPRESSION_STRATEGY_FILTERED , GD_PNG_COMPRESSION_STRATEGY_HUFFMAN_ONLY , GD_PNG_COMPRESSION_STRATEGY_RLE ,
  GD_PNG_COMPRESSION_STRATEGY_FIXED
}
 PNG compression strategy values for gdPngWriteOptions. More...
 

Functions

gdImagePtr gdImageCreateFromPng (FILE *fd)
 Create an image from a PNG stdio file.
 
gdImagePtr gdImageCreateFromPngCtx (gdIOCtxPtr in)
 Create an image from PNG data read through a gdIOCtx.
 
gdImagePtr gdImageCreateFromPngPtr (int size, void *data)
 Create an image from a PNG memory buffer.
 
void gdImagePng (gdImagePtr im, FILE *out)
 Write an image as PNG data to a stdio file.
 
void gdImagePngCtx (gdImagePtr im, gdIOCtxPtr out)
 Write an image as PNG data to a gdIOCtx.
 
void gdImagePngEx (gdImagePtr im, FILE *out, int level)
 Write an image as PNG data to a stdio file with a compression level.
 
void gdImagePngCtxEx (gdImagePtr im, gdIOCtxPtr out, int level)
 Write an image as PNG data to a gdIOCtx with a compression level.
 
void * gdImagePngPtr (gdImagePtr im, int *size)
 Write an image as PNG data to a newly allocated memory buffer.
 
void * gdImagePngPtrEx (gdImagePtr im, int *size, int level)
 Write an image as PNG data to a memory buffer with a compression level.
 
void gdPngWriteOptionsInit (gdPngWriteOptions *options)
 Initialize PNG write options with default values.
 
void gdPngInfoInit (gdPngInfo *info)
 Initialize a gdPngInfo structure with default values.
 
int gdImagePngWithOptions (gdImagePtr im, FILE *out, const gdPngWriteOptions *options)
 Write an image as PNG data to a stdio file using write options.
 
int gdImagePngCtxWithOptions (gdImagePtr im, gdIOCtxPtr out, const gdPngWriteOptions *options)
 Write an image as PNG data to a gdIOCtx using write options.
 
void * gdImagePngPtrWithOptions (gdImagePtr im, int *size, const gdPngWriteOptions *options)
 Write an image as PNG data to a memory buffer using write options.
 
int gdPngGetInfo (FILE *in, gdPngInfo *info)
 Read PNG header information from a stdio file.
 
int gdPngGetInfoCtx (gdIOCtxPtr in, gdPngInfo *info)
 Read PNG header information from a gdIOCtx.
 
int gdPngGetInfoPtr (int size, const void *data, gdPngInfo *info)
 Read PNG header information from a memory buffer.
 
const char * gdPngGetVersionString (void)
 Return a string describing the linked libpng version.
 

Detailed Description

PNG image reading and writing support.

PNG support preserves palette images as palette-based gd images and reads truecolor PNG data as truecolor gd images. PNG output is palette-aware, supports alpha, metadata, compression settings, and libpng filter options.

gdImagePtr im;
int black, white;
FILE *out;
im = gdImageCreate(100, 100);
if (im == NULL) {
fprintf(stderr, "Unable to create image\n");
exit(1);
}
white = gdImageColorAllocate(im, 255, 255, 255);
black = gdImageColorAllocate(im, 0, 0, 0);
gdImageRectangle(im, 0, 0, 99, 99, black);
out = fopen("rect.png", "wb");
if (out == NULL) {
fprintf(stderr, "Unable to open output file\n");
gdImageDestroy(im);
exit(1);
}
gdImagePngEx(im, out, 9);
fclose(out);
gdImageDestroy(im);
void gdImageRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color)
Draws a rectangle.
Definition gd.c:2239
void gdImagePngEx(gdImagePtr im, FILE *out, int level)
Write an image as PNG data to a stdio file with a compression level.
Definition gd_png.c:1683
Write an image as JPEG data to a gdIOCtx.

Macro Definition Documentation

◆ GD_PNG_FILTER_ALL

#define GD_PNG_FILTER_ALL
Value:
#define GD_PNG_FILTER_PAETH
Definition gd.h:790
#define GD_PNG_FILTER_UP
Definition gd.h:786
#define GD_PNG_FILTER_AVERAGE
Definition gd.h:788
#define GD_PNG_FILTER_SUB
Definition gd.h:784
#define GD_PNG_FILTER_NONE
Definition gd.h:782

Enable all PNG row filters.

◆ GD_PNG_FILTER_AUTO

#define GD_PNG_FILTER_AUTO   0U

Let libpng choose PNG row filters automatically.

◆ GD_PNG_FILTER_AVERAGE

#define GD_PNG_FILTER_AVERAGE   (1U << 3)

Enable the PNG "Average" row filter.

◆ GD_PNG_FILTER_NONE

#define GD_PNG_FILTER_NONE   (1U << 0)

Enable the PNG "None" row filter.

◆ GD_PNG_FILTER_PAETH

#define GD_PNG_FILTER_PAETH   (1U << 4)

Enable the PNG "Paeth" row filter.

◆ GD_PNG_FILTER_SUB

#define GD_PNG_FILTER_SUB   (1U << 1)

Enable the PNG "Sub" row filter.

◆ GD_PNG_FILTER_UP

#define GD_PNG_FILTER_UP   (1U << 2)

Enable the PNG "Up" row filter.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

PNG compression strategy values for gdPngWriteOptions.

Enumerator
GD_PNG_COMPRESSION_STRATEGY_DEFAULT 

Use zlib's default strategy.

GD_PNG_COMPRESSION_STRATEGY_FILTERED 

Prefer zlib's filtered-data strategy.

GD_PNG_COMPRESSION_STRATEGY_HUFFMAN_ONLY 

Use Huffman coding only.

GD_PNG_COMPRESSION_STRATEGY_RLE 

Use zlib's run-length encoding strategy.

GD_PNG_COMPRESSION_STRATEGY_FIXED 

Use zlib's fixed Huffman codes strategy.

Function Documentation

◆ gdImageCreateFromPng()

gdImagePtr gdImageCreateFromPng ( FILE *  fd)

Create an image from a PNG stdio file.

Parameters
fdPointer to the input FILE stream.
Returns
Returns a gdImagePtr on success, or NULL on failure.

◆ gdImageCreateFromPngCtx()

gdImagePtr gdImageCreateFromPngCtx ( gdIOCtxPtr  in)

Create an image from PNG data read through a gdIOCtx.

Parameters
inPointer to the gdIOCtx input context.
Returns
Returns a gdImagePtr on success, or NULL on failure.

◆ gdImageCreateFromPngPtr()

gdImagePtr gdImageCreateFromPngPtr ( int  size,
void *  data 
)

Create an image from a PNG memory buffer.

Parameters
sizeSize of the PNG memory buffer in bytes.
dataPointer to the PNG memory buffer.
Returns
Returns a gdImagePtr on success, or NULL on failure.

◆ gdImagePng()

void gdImagePng ( gdImagePtr  im,
FILE *  out 
)

Write an image as PNG data to a stdio file.

Parameters
imThe image to write.
outThe stdio file to write the PNG data to.

◆ gdImagePngCtx()

void gdImagePngCtx ( gdImagePtr  im,
gdIOCtxPtr  out 
)

Write an image as PNG data to a gdIOCtx.

Parameters
imThe image to write.
outThe gdIOCtx to write the PNG data to.

◆ gdImagePngCtxEx()

void gdImagePngCtxEx ( gdImagePtr  im,
gdIOCtxPtr  out,
int  level 
)

Write an image as PNG data to a gdIOCtx with a compression level.

Parameters
imThe image to write.
outThe gdIOCtx to write the PNG data to.
levelCompression level: 0 for no compression, 1-9 for zlib levels, or -1 for the default.

◆ gdImagePngCtxWithOptions()

int gdImagePngCtxWithOptions ( gdImagePtr  im,
gdIOCtxPtr  out,
const gdPngWriteOptions options 
)

Write an image as PNG data to a gdIOCtx using write options.

Parameters
imThe image to write.
outThe gdIOCtx to write the PNG data to.
optionsPointer to a gdPngWriteOptions structure, or NULL for defaults.
Returns
Returns 0 on success, or 1 on failure.

◆ gdImagePngEx()

void gdImagePngEx ( gdImagePtr  im,
FILE *  out,
int  level 
)

Write an image as PNG data to a stdio file with a compression level.

Parameters
imThe image to write.
outThe stdio file to write the PNG data to.
levelCompression level: 0 for no compression, 1-9 for zlib levels, or -1 for the default.

◆ gdImagePngPtr()

void * gdImagePngPtr ( gdImagePtr  im,
int *  size 
)

Write an image as PNG data to a newly allocated memory buffer.

Parameters
imThe image to write.
sizePointer to an integer that receives the returned buffer size.
Returns
A pointer to the newly allocated PNG data, or NULL on failure.

◆ gdImagePngPtrEx()

void * gdImagePngPtrEx ( gdImagePtr  im,
int *  size,
int  level 
)

Write an image as PNG data to a memory buffer with a compression level.

Parameters
imThe image to write.
sizePointer to an integer that receives the returned buffer size.
levelCompression level: 0 for no compression, 1-9 for zlib levels, or -1 for the default.
Returns
A pointer to the newly allocated PNG data, or NULL on failure.

◆ gdImagePngPtrWithOptions()

void * gdImagePngPtrWithOptions ( gdImagePtr  im,
int *  size,
const gdPngWriteOptions options 
)

Write an image as PNG data to a memory buffer using write options.

Parameters
imThe image to write.
sizePointer to an integer that receives the returned buffer size.
optionsPointer to a gdPngWriteOptions structure, or NULL for defaults.
Returns
A pointer to the newly allocated PNG data, or NULL on failure.

◆ gdImagePngWithOptions()

int gdImagePngWithOptions ( gdImagePtr  im,
FILE *  out,
const gdPngWriteOptions options 
)

Write an image as PNG data to a stdio file using write options.

Parameters
imThe image to write.
outThe stdio file to write the PNG data to.
optionsPointer to a gdPngWriteOptions structure, or NULL for defaults.
Returns
Returns 0 on success, or 1 on failure.

◆ gdPngGetInfo()

int gdPngGetInfo ( FILE *  in,
gdPngInfo info 
)

Read PNG header information from a stdio file.

Parameters
inPointer to the input FILE stream.
infoPointer to the gdPngInfo structure to populate.
Returns
Returns 0 on success, or 1 on failure.

◆ gdPngGetInfoCtx()

int gdPngGetInfoCtx ( gdIOCtxPtr  in,
gdPngInfo info 
)

Read PNG header information from a gdIOCtx.

Parameters
inPointer to the gdIOCtx input context.
infoPointer to the gdPngInfo structure to populate.
Returns
Returns 0 on success, or 1 on failure.

◆ gdPngGetInfoPtr()

int gdPngGetInfoPtr ( int  size,
const void *  data,
gdPngInfo info 
)

Read PNG header information from a memory buffer.

Parameters
sizeSize of the PNG memory buffer in bytes.
dataPointer to the PNG memory buffer.
infoPointer to the gdPngInfo structure to populate.
Returns
Returns 0 on success, or 1 on failure.

◆ gdPngGetVersionString()

const char * gdPngGetVersionString ( void  )

Return a string describing the linked libpng version.

Returns
Returns the linked libpng version string.

◆ gdPngInfoInit()

void gdPngInfoInit ( gdPngInfo info)

Initialize a gdPngInfo structure with default values.

Parameters
infoPointer to the gdPngInfo structure to initialize.

◆ gdPngWriteOptionsInit()

void gdPngWriteOptionsInit ( gdPngWriteOptions options)

Initialize PNG write options with default values.

Parameters
optionsPointer to the gdPngWriteOptions structure to initialize.