Blame docs/naturaldocs/html/files/gd_png-c.html

Packit ed3af9
Packit ed3af9
Packit ed3af9
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>PNG IO</title><link rel="stylesheet" type="text/css" href="../styles/main.css"><script language=JavaScript src="../javascript/main.js"></script><script language=JavaScript src="../javascript/prettify.js"></script><script language=JavaScript src="../javascript/searchdata.js"></script></head><body class="ContentPage" onLoad="NDOnLoad();prettyPrint();"><script language=JavaScript>
Packit ed3af9
if (browserType) {document.write("
");if (browserVer) {document.write("
"); }}// --></script>
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9

PNG IO

Read and write PNG images.

Summary
PNG IORead and write PNG images.
Functions
gdImageCreateFromPnggdImageCreateFromPng is called to load images from PNG format files.
gdImageCreateFromPngPtrSee gdImageCreateFromPng.
gdImageCreateFromPngCtxSee gdImageCreateFromPng.
gdImagePngExgdImagePngEx outputs the specified image to the specified file in PNG format.
gdImagePngEquivalent to calling gdImagePngEx with compression of -1.
gdImagePngPtrEquivalent to calling gdImagePngPtrEx with compression of -1.
gdImagePngPtrExIdentical to gdImagePngEx except that it returns a pointer to a memory area with the PNG data.
gdImagePngCtxEquivalent to calling gdImagePngCtxEx with compression of -1.
gdImagePngCtxExOutputs the given image as PNG data, but using a gdIOCtx instead of a file.
Packit ed3af9
Packit ed3af9

Functions

Packit ed3af9
Packit ed3af9

gdImageCreateFromPng

gdImagePtr gdImageCreateFromPng (FILE *inFile)

gdImageCreateFromPng is called to load images from PNG format files.  Invoke gdImageCreateFromPng with an already opened pointer to a FILE containing the desired image.  gdImageCreateFromPng returns a gdImagePtr to the new image, or NULL if unable to load the image (most often because the file is corrupt or does not contain a PNG image).  gdImageCreateFromPng does not close the file.  You can inspect the sx and sy members of the image to determine its size.  The image must eventually be destroyed using gdImageDestroy().

If the PNG image being loaded is a truecolor image, the resulting gdImagePtr will refer to a truecolor image.  If the PNG image being loaded is a palette or grayscale image, the resulting gdImagePtr will refer to a palette image. gd retains only 8 bits of resolution for each of the red, green and blue channels, and only 7 bits of resolution for the alpha channel.  The former restriction affects only a handful of very rare 48-bit color and 16-bit grayscale PNG images.  The second restriction affects all semitransparent PNG images, but the difference is essentially invisible to the eye.  7 bits of alpha channel resolution is, in practice, quite a lot.

Variants

gdImageCreateFromPngPtr creates an image from PNG data (i.e. the contents of a PNG file) already in memory.

gdImageCreateFromPngCtx reads in an image using the functions in a gdIOCtx struct.

gdImageCreateFromPngSource is similar to gdImageCreateFromPngCtx but uses the old gdSource interface.  It is obsolete.

Parameters

infileThe input FILE pointer.

Returns

A pointer to the new image or NULL if an error occurred.

Example

gdImagePtr im;
Packit ed3af9
... inside a function ...
Packit ed3af9
FILE *in;
Packit ed3af9
in = fopen("mypng.png", "rb");
Packit ed3af9
im = gdImageCreateFromPng(in);
Packit ed3af9
fclose(in);
Packit ed3af9
// ... Use the image ...
Packit ed3af9
gdImageDestroy(im);
Packit ed3af9
Packit ed3af9

gdImageCreateFromPngPtr

gdImagePtr gdImageCreateFromPngPtr (int size,
void *data)

See gdImageCreateFromPng.

Packit ed3af9
Packit ed3af9

gdImageCreateFromPngCtx

gdImagePtr gdImageCreateFromPngCtx (gdIOCtx *infile)

See gdImageCreateFromPng.

Packit ed3af9
Packit ed3af9

gdImagePngEx

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

gdImagePngEx outputs the specified image to the specified file in PNG format.  The file must be open for writing.  Under MSDOS and all versions of Windows, it is important to use “wb” as opposed to simply “w” as the mode when opening the file, and under Unix there is no penalty for doing so.  gdImagePngEx does not close the file; your code must do so.

In addition, gdImagePngEx allows the level of compression to be specified.  A compression level of 0 means “no compression.”  A compression level of 1 means “compressed, but as quickly as possible.”  A compression level of 9 means “compressed as much as possible to produce the smallest possible file.”  A compression level of -1 will use the default compression level at the time zlib was compiled on your system.

Variants

gdImagePng is equivalent to calling gdImagePngEx with compression of -1.

gdImagePngCtx and gdImagePngCtxEx write via a gdIOCtx instead of a file handle.

gdImagePngPtr and gdImagePngPtrEx store the image file to memory.

Parameters

imthe image to write
outFilethe output FILE* object.
levelcompression level: 0 -> none, 1-9 -> level, -1 -> default

Returns

Nothing.

Example

gdImagePtr im;
Packit ed3af9
int black, white;
Packit ed3af9
FILE *out;
Packit ed3af9
Packit ed3af9
im = gdImageCreate(100, 100);              // Create the image
Packit ed3af9
white = gdImageColorAllocate(im, 255, 255, 255); // Alloc background
Packit ed3af9
black = gdImageColorAllocate(im, 0, 0, 0); // Allocate drawing color
Packit ed3af9
gdImageRectangle(im, 0, 0, 99, 99, black); // Draw rectangle
Packit ed3af9
out = fopen("rect.png", "wb");             // Open output file (binary)
Packit ed3af9
gdImagePngEx(im, out, 9);                  // Write PNG, max compression
Packit ed3af9
fclose(out);                               // Close file
Packit ed3af9
gdImageDestroy(im);                        // Destroy image
Packit ed3af9
Packit ed3af9

gdImagePng

void gdImagePng (gdImagePtr im,
FILE *outFile)

Equivalent to calling gdImagePngEx with compression of -1.

Parameters

imthe image to save.
outFilethe output FILE*.

Returns

Nothing.

Packit ed3af9
Packit ed3af9

gdImagePngPtr

void * gdImagePngPtr (gdImagePtr im,
int *size)

Equivalent to calling gdImagePngPtrEx with compression of -1.

See gdImagePngEx for more information.

Parameters

imthe image to save.
sizeOutput: size in bytes of the result.

Returns

A pointer to memory containing the image data or NULL on error.

Packit ed3af9
Packit ed3af9

gdImagePngPtrEx

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

Identical to gdImagePngEx except that it returns a pointer to a memory area with the PNG data.  This memory must be freed by the caller when it is no longer needed.  **The caller must invoke gdFree(), not free()**

The ‘size’ parameter receives the total size of the block of memory.

See gdImagePngEx for more information.

Parameters

imthe image to save.
sizeOutput: size in bytes of the result.
levelcompression level: 0 -> none, 1-9 -> level, -1 -> default

Returns

A pointer to memory containing the image data or NULL on error.

Packit ed3af9
Packit ed3af9

gdImagePngCtx

void gdImagePngCtx (gdImagePtr im,
gdIOCtx *outfile)

Equivalent to calling gdImagePngCtxEx with compression of -1.  See gdImagePngEx for more information.

Parameters

imthe image to save.
outfilethe gdIOCtx to write to.

Returns

Nothing.

Packit ed3af9
Packit ed3af9

gdImagePngCtxEx

void gdImagePngCtxEx (gdImagePtr im,
gdIOCtx *outfile,
int level)

Outputs the given image as PNG data, but using a gdIOCtx instead of a file.  See <gdIamgePnEx>.

Parameters

imthe image to save.
outfilethe gdIOCtx to write to.
levelcompression level: 0 -> none, 1-9 -> level, -1 -> default

Returns

Nothing.

Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
var searchPanel = new SearchPanel("searchPanel", "HTML", "../search");
Packit ed3af9
--></script>
<input type=text id=MSearchField value=Search onFocus="searchPanel.OnSearchFieldFocus(true)" onBlur="searchPanel.OnSearchFieldFocus(false)" onKeyUp="searchPanel.OnSearchFieldChange()"><select id=MSearchType onFocus="searchPanel.OnSearchTypeFocus(true)" onBlur="searchPanel.OnSearchTypeFocus(false)" onChange="searchPanel.OnSearchTypeChange()"><option id=MSearchEverything selected value="General">Everything</option><option value="Constants">Constants</option><option value="Files">Files</option><option value="Functions">Functions</option><option value="Macros">Macros</option><option value="Types">Types</option></select>
<script language=JavaScript>
Packit ed3af9
HideAllBut([1], 4);// --></script>
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
gdImagePtr gdImageCreateFromPng (FILE *inFile)
gdImageCreateFromPng is called to load images from PNG format files.
gdImagePtr gdImageCreateFromPngPtr (int size,
void *data)
See gdImageCreateFromPng.
gdImagePtr gdImageCreateFromPngCtx (gdIOCtx *infile)
See gdImageCreateFromPng.
void gdImagePngEx (gdImagePtr im,
FILE *outFile,
int level)
gdImagePngEx outputs the specified image to the specified file in PNG format.
void gdImagePng (gdImagePtr im,
FILE *outFile)
Equivalent to calling gdImagePngEx with compression of -1.
void * gdImagePngPtr (gdImagePtr im,
int *size)
Equivalent to calling gdImagePngPtrEx with compression of -1.
void * gdImagePngPtrEx (gdImagePtr im,
int *size,
int level)
Identical to gdImagePngEx except that it returns a pointer to a memory area with the PNG data.
void gdImagePngCtx (gdImagePtr im,
gdIOCtx *outfile)
Equivalent to calling gdImagePngCtxEx with compression of -1.
void gdImagePngCtxEx (gdImagePtr im,
gdIOCtx *outfile,
int level)
Outputs the given image as PNG data, but using a gdIOCtx instead of a file.
gdIOCtx structures hold function pointers for doing image IO.
The data structure in which gd stores images.
gdImagePtr gdImageCreateFromPngSource (gdSourcePtr inSource)
See gdImageCreateFromPng for documentation.
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
Packit ed3af9
<iframe src="" frameborder=0 name=MSearchResults id=MSearchResults></iframe>Close
Packit ed3af9
Packit ed3af9
Packit ed3af9
<script language=JavaScript>
Packit ed3af9
if (browserType) {if (browserVer) {document.write(""); }document.write("");}// --></script></body></html>