LibGd 2.4.0-dev
GD Graphics library
Loading...
Searching...
No Matches

Read and write libgd's native .gd image format. More...

Collaboration diagram for GD:

GD Reading

gdImagePtr gdImageCreateFromGd (FILE *in)
 Create an image from a GD stdio file.
 
gdImagePtr gdImageCreateFromGdCtx (gdIOCtxPtr in)
 Create an image from GD data read through a gdIOCtx.
 
gdImagePtr gdImageCreateFromGdPtr (int size, void *data)
 Create an image from a GD memory buffer.
 

GD Writing

void * gdImageGdPtr (gdImagePtr im, int *size)
 Write an image as GD data to a newly allocated memory buffer.
 
void gdImageGd (gdImagePtr im, FILE *out)
 Write an image as GD data to a stdio file.
 

Detailed Description

Read and write libgd's native .gd image format.

The GD format is libgd's own historical image dump format. It is obsolete for interchange and should generally be used only for development, testing, or compatibility with existing .gd assets. For compressed or portable image exchange, prefer formats such as PNG, JPEG, WebP, or AVIF.

gd can read GD 1.x palette .gd files and GD 2.x palette or truecolor .gd files. The writer always emits the GD 2.x .gd format, not the related GD2 chunked format documented separately by the GD2 APIs. Returned gdImagePtr images are owned by the caller and must be destroyed with gdImageDestroy.

gdImagePtr im, roundtrip;
void *data;
int size;
im = gdImageCreate(100, 100);
gdImageColorAllocate(im, 255, 255, 255);
gdImageColorAllocate(im, 0, 0, 0);
gdImageLine(im, 0, 0, 99, 99, 1);
data = gdImageGdPtr(im, &size);
if (data != NULL) {
roundtrip = gdImageCreateFromGdPtr(size, data);
gdFree(data);
if (roundtrip != NULL) {
gdImageDestroy(roundtrip);
}
}
gdImageDestroy(im);
void * gdImageGdPtr(gdImagePtr im, int *size)
Write an image as GD data to a newly allocated memory buffer.
Definition gd_gd.c:376
gdImagePtr gdImageCreateFromGdPtr(int size, void *data)
Create an image from a GD memory buffer.
Definition gd_gd.c:354
Write an image as JPEG data to a gdIOCtx.

Function Documentation

◆ gdImageCreateFromGd()

gdImagePtr gdImageCreateFromGd ( FILE *  in)

Create an image from a GD stdio file.

gdImageCreateFromGd() reads from the current position of in and does not close it. On success, the returned image is owned by the caller and must be destroyed with gdImageDestroy.

Parameters
inPointer to the GD FILE stream to read.
Returns
A newly allocated image, or NULL on error.

◆ gdImageCreateFromGdCtx()

gdImagePtr gdImageCreateFromGdCtx ( gdIOCtxPtr  in)

Create an image from GD data read through a gdIOCtx.

gdImageCreateFromGdCtx() reads from in and does not close it. On success, the returned image is owned by the caller and must be destroyed with gdImageDestroy.

Parameters
inPointer to the gdIOCtx input context.
Returns
A newly allocated image, or NULL on error.

◆ gdImageCreateFromGdPtr()

gdImagePtr gdImageCreateFromGdPtr ( int  size,
void *  data 
)

Create an image from a GD memory buffer.

gdImageCreateFromGdPtr() borrows data for the duration of the call. The caller retains ownership of the input buffer. On success, the returned image is owned by the caller and must be destroyed with gdImageDestroy.

Parameters
sizeSize of the GD memory buffer in bytes.
dataPointer to the GD memory buffer.
Returns
A newly allocated image, or NULL on error.

◆ gdImageGd()

void gdImageGd ( gdImagePtr  im,
FILE *  out 
)

Write an image as GD data to a stdio file.

gdImageGd() writes the image in GD 2.x .gd format. The image and out stream are borrowed for the duration of the call, and out is not closed by gd.

Parameters
imThe image to write.
outPointer to the output FILE stream.

◆ gdImageGdPtr()

void * gdImageGdPtr ( gdImagePtr  im,
int *  size 
)

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

gdImageGdPtr() writes the image in GD 2.x .gd format. The image is borrowed for the duration of the call. On success, the returned buffer is owned by the caller and must be freed with gdFree().

Parameters
imThe image to write.
sizeOutput location for the returned buffer size in bytes.
Returns
A newly allocated GD buffer, or NULL on error.