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

JPEG image reading and writing support. More...

Collaboration diagram for JPEG:

Namespaces

namespace  im
 Write an image as JPEG data to a gdIOCtx.
 

Data Structures

struct  gdJpegInfo
 Basic information read from a JPEG header. More...
 
struct  gdJpegReadOptions
 Options for reading JPEG data. More...
 
struct  gdJpegWriteOptions
 Options for writing JPEG data. More...
 

Enumerations

enum  {
  GD_JPEG_COLOR_SPACE_UNKNOWN = 0 , GD_JPEG_COLOR_SPACE_GRAYSCALE = 1 , GD_JPEG_COLOR_SPACE_RGB = 2 , GD_JPEG_COLOR_SPACE_YCBCR = 3 ,
  GD_JPEG_COLOR_SPACE_CMYK = 4 , GD_JPEG_COLOR_SPACE_YCCK = 5
}
 JPEG color space identifiers reported by gdJpegInfo. More...
 
enum  { GD_JPEG_DENSITY_UNIT_NONE = 0 , GD_JPEG_DENSITY_UNIT_DPI = 1 , GD_JPEG_DENSITY_UNIT_DPCM = 2 }
 JPEG density units reported by gdJpegInfo. More...
 
enum  { GD_JPEG_DCT_DEFAULT = 0 , GD_JPEG_DCT_SLOW = 1 , GD_JPEG_DCT_FAST = 2 , GD_JPEG_DCT_FLOAT = 3 }
 JPEG DCT method options for gdJpegReadOptions. More...
 

Functions

void gdJpegInfoInit (gdJpegInfo *info)
 Initialize a gdJpegInfo structure with default values.
 
void gdJpegReadOptionsInit (gdJpegReadOptions *options)
 Initialize JPEG read options with default values.
 
void gdJpegWriteOptionsInit (gdJpegWriteOptions *options)
 Initialize JPEG write options with default values.
 
int gdJpegGetInfo (FILE *infile, gdJpegInfo *info)
 Read JPEG header information from a stdio file.
 
int gdJpegGetInfoCtx (gdIOCtxPtr infile, gdJpegInfo *info)
 Read JPEG header information from a gdIOCtx.
 
int gdJpegGetInfoPtr (int size, const void *data, gdJpegInfo *info)
 Read JPEG header information from a memory buffer.
 
gdImagePtr gdImageCreateFromJpeg (FILE *infile)
 Create an image from a JPEG stdio file.
 
gdImagePtr gdImageCreateFromJpegEx (FILE *infile, int ignore_warning)
 Create an image from a JPEG stdio file, controlling warning handling.
 
gdImagePtr gdImageCreateFromJpegCtx (gdIOCtxPtr infile)
 Create an image from JPEG data read through a gdIOCtx.
 
gdImagePtr gdImageCreateFromJpegCtxEx (gdIOCtxPtr infile, int ignore_warning)
 Create an image from a JPEG gdIOCtx, controlling warning handling.
 
gdImagePtr gdImageCreateFromJpegCtxWithOptions (gdIOCtxPtr infile, const gdJpegReadOptions *options)
 Create an image from a JPEG gdIOCtx and collect metadata.
 
gdImagePtr gdImageCreateFromJpegPtr (int size, void *data)
 Create an image from a JPEG memory buffer.
 
gdImagePtr gdImageCreateFromJpegPtrEx (int size, void *data, int ignore_warning)
 Create an image from a JPEG memory buffer, controlling warning handling.
 
gdImagePtr gdImageCreateFromJpegPtrWithOptions (int size, void *data, const gdJpegReadOptions *options)
 Create an image from a JPEG memory buffer using read options.
 
const char * gdJpegGetVersionString ()
 Create an image from a JPEG memory buffer and collect metadata.
 
void gdImageJpeg (gdImagePtr im, FILE *out, int quality)
 Write an image as JPEG data to a stdio file.
 
int gdImageJpegWithOptions (gdImagePtr im, FILE *out, const gdJpegWriteOptions *options)
 Write an image as JPEG data to a gdIOCtx with metadata.
 
int gdImageJpegCtxWithOptions (gdImagePtr im, gdIOCtxPtr out, const gdJpegWriteOptions *options)
 Write an image as JPEG data to a gdIOCtx using write options.
 
void * gdImageJpegPtr (gdImagePtr im, int *size, int quality)
 Write an image as JPEG data to a newly allocated memory buffer.
 
void * gdImageJpegPtrWithOptions (gdImagePtr im, int *size, const gdJpegWriteOptions *options)
 Write an image as JPEG data to a memory buffer with metadata.
 

Detailed Description

JPEG image reading and writing support.

GD supports a range of raster codecs for loading and saving images, including JPEG, PNG, GIF, WebP, and others. Each codec is exposed as its own subgroup with format-specific options and functions.

gdImagePtr im;
int black, white;
FILE *out;
im = gdImageCreate(100, 100);
if (im == NULL) {
fprintf(stderr, "Unable to create image\n");
exit(1);
}
// Allocate background
white = gdImageColorAllocate(im, 255, 255, 255);
// Allocate drawing color
black = gdImageColorAllocate(im, 0, 0, 0);
// Draw rectangle
gdImageRectangle(im, 0, 0, 99, 99, black);
// Open output file in binary mode
out = fopen("rect.jpg", "wb");
if (out == NULL) {
fprintf(stderr, "Unable to open output file\n");
exit(1);
}
// Write JPEG using default quality
gdImageJpeg(im, out, -1);
// Close file
fclose(out);
// Destroy image
gdImageDestroy(im);
void gdImageRectangle(gdImagePtr im, int x1, int y1, int x2, int y2, int color)
Draws a rectangle.
Definition gd.c:2239
void gdImageJpeg(gdImagePtr im, FILE *out, int quality)
Write an image as JPEG data to a stdio file.
Definition gd_jpeg.c:1730
Write an image as JPEG data to a gdIOCtx.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

JPEG color space identifiers reported by gdJpegInfo.

Enumerator
GD_JPEG_COLOR_SPACE_UNKNOWN 

Unknown or unsupported JPEG color space.

GD_JPEG_COLOR_SPACE_GRAYSCALE 

Grayscale JPEG color space.

GD_JPEG_COLOR_SPACE_RGB 

RGB JPEG color space.

GD_JPEG_COLOR_SPACE_YCBCR 

YCbCr JPEG color space.

GD_JPEG_COLOR_SPACE_CMYK 

CMYK JPEG color space.

GD_JPEG_COLOR_SPACE_YCCK 

YCCK JPEG color space.

◆ anonymous enum

anonymous enum

JPEG density units reported by gdJpegInfo.

Enumerator
GD_JPEG_DENSITY_UNIT_NONE 

No density unit is specified.

GD_JPEG_DENSITY_UNIT_DPI 

Density is measured in dots per inch.

GD_JPEG_DENSITY_UNIT_DPCM 

Density is measured in dots per centimeter.

◆ anonymous enum

anonymous enum

JPEG DCT method options for gdJpegReadOptions.

Enumerator
GD_JPEG_DCT_DEFAULT 

Use the JPEG library default DCT method.

GD_JPEG_DCT_SLOW 

Use the slow integer DCT method.

GD_JPEG_DCT_FAST 

Use the fast integer DCT method.

GD_JPEG_DCT_FLOAT 

Use the floating-point DCT method.

Function Documentation

◆ gdImageCreateFromJpeg()

gdImagePtr gdImageCreateFromJpeg ( FILE *  infile)

Create an image from a JPEG stdio file.

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

◆ gdImageCreateFromJpegCtx()

gdImagePtr gdImageCreateFromJpegCtx ( gdIOCtxPtr  infile)

Create an image from JPEG data read through a gdIOCtx.

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

◆ gdImageCreateFromJpegCtxEx()

gdImagePtr gdImageCreateFromJpegCtxEx ( gdIOCtxPtr  infile,
int  ignore_warning 
)

Create an image from a JPEG gdIOCtx, controlling warning handling.

Parameters
infilePointer to the gdIOCtx input context.
ignore_warningNon-zero to suppress recoverable JPEG warnings.
Returns
Returns a gdImagePtr on success, or NULL on failure.

◆ gdImageCreateFromJpegCtxWithOptions()

gdImagePtr gdImageCreateFromJpegCtxWithOptions ( gdIOCtxPtr  infile,
const gdJpegReadOptions options 
)

Create an image from a JPEG gdIOCtx and collect metadata.

Parameters
infilePointer to the gdIOCtx input context.
metadataPointer to a gdImageMetadata structure to collect metadata.
Returns
Returns a gdImagePtr on success, or NULL on failure.

Create an image from a JPEG gdIOCtx with warning control and metadata collection.

Parameters
infilePointer to the gdIOCtx input context.
ignore_warningNon-zero to suppress recoverable JPEG warnings.
metadataPointer to a gdImageMetadata structure to collect metadata.
Returns
Returns a gdImagePtr on success, or NULL on failure.

Create an image from a JPEG gdIOCtx using read options.

Parameters
infilePointer to the gdIOCtx input context.
optionsPointer to a gdJpegReadOptions structure specifying read options.
Returns
Returns a gdImagePtr on success, or NULL on failure.

◆ gdImageCreateFromJpegEx()

gdImagePtr gdImageCreateFromJpegEx ( FILE *  infile,
int  ignore_warning 
)

Create an image from a JPEG stdio file, controlling warning handling.

Parameters
infilePointer to the input FILE stream.
ignore_warningNon-zero to suppress recoverable JPEG warnings.
Returns
Returns a gdImagePtr on success, or NULL on failure.

◆ gdImageCreateFromJpegPtr()

gdImagePtr gdImageCreateFromJpegPtr ( int  size,
void *  data 
)

Create an image from a JPEG memory buffer.

Parameters
sizeThe size of the JPEG memory buffer.
dataPointer to the JPEG memory buffer.
Returns
Returns a gdImagePtr on success, or NULL on failure.

◆ gdImageCreateFromJpegPtrEx()

gdImagePtr gdImageCreateFromJpegPtrEx ( int  size,
void *  data,
int  ignore_warning 
)

Create an image from a JPEG memory buffer, controlling warning handling.

Parameters
sizeThe size of the JPEG memory buffer.
dataPointer to the JPEG memory buffer.
ignore_warningNon-zero to suppress recoverable JPEG warnings.
Returns
Returns a gdImagePtr on success, or NULL on failure.

◆ gdImageCreateFromJpegPtrWithOptions()

gdImagePtr gdImageCreateFromJpegPtrWithOptions ( int  size,
void *  data,
const gdJpegReadOptions options 
)

Create an image from a JPEG memory buffer using read options.

Parameters
sizeThe size of the JPEG memory buffer.
dataPointer to the JPEG memory buffer.
optionsPointer to a gdJpegReadOptions structure specifying read options.
Returns
Returns a gdImagePtr on success, or NULL on failure.

◆ gdImageJpeg()

void gdImageJpeg ( gdImagePtr  im,
FILE *  out,
int  quality 
)

Write an image as JPEG data to a stdio file.

100 is the highest quality (there is always a little loss with JPEG). 0 is the lowest quality. 10 is about the lowest useful setting.

Parameters
imThe image to write.
outThe stdio file to write the JPEG data to.
qualityThe JPEG quality (0-100).

◆ gdImageJpegCtxWithOptions()

int gdImageJpegCtxWithOptions ( gdImagePtr  im,
gdIOCtxPtr  out,
const gdJpegWriteOptions options 
)

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

Parameters
imThe image to write.
outThe gdIOCtx to write the JPEG data to.
optionsPointer to a gdJpegWriteOptions struct containing the desired write options.
Returns
Returns 0 on success, or a negative value on error.

◆ gdImageJpegPtr()

void * gdImageJpegPtr ( gdImagePtr  im,
int *  size,
int  quality 
)

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

Result must be freed with gdFree(). The image is borrowed for the duration of the call.

Parameters
imThe image to write.
sizePointer to an integer that will receive the size of the returned buffer.
qualityThe JPEG quality (0-100).
Returns
A pointer to the newly allocated buffer containing the JPEG data, or NULL on failure.

◆ gdImageJpegPtrWithOptions()

void * gdImageJpegPtrWithOptions ( gdImagePtr  im,
int *  size,
const gdJpegWriteOptions options 
)

Write an image as JPEG data to a memory buffer with metadata.

Parameters
imThe image to write.
sizePointer to an integer that will receive the size of the returned buffer.
qualityThe JPEG quality (0-100).
metadataPointer to a gdImageMetadata structure containing the metadata to include in the JPEG file.
Returns
A pointer to the newly allocated buffer containing the JPEG data, or NULL on failure.

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

Parameters
imThe image to write.
sizePointer to an integer that will receive the size of the returned buffer.
optionsPointer to a gdJpegWriteOptions struct containing the desired write options.
Returns
A pointer to the newly allocated buffer containing the JPEG data, or NULL on failure.

◆ gdImageJpegWithOptions()

int gdImageJpegWithOptions ( gdImagePtr  im,
FILE *  out,
const gdJpegWriteOptions options 
)

Write an image as JPEG data to a gdIOCtx with metadata.

Parameters
imThe image to write.
outThe gdIOCtx to write the JPEG data to.
qualityThe JPEG quality (0-100).
metadataPointer to a gdImageMetadata structure containing the metadata to include in the JPEG file.

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

Parameters
imThe image to write.
outThe stdio file to write the JPEG data to.
optionsPointer to a gdJpegWriteOptions struct containing the desired write options.
Returns
Returns 0 on success, or a negative value on error.

◆ gdJpegGetInfo()

int gdJpegGetInfo ( FILE *  infile,
gdJpegInfo info 
)

Read JPEG header information from a stdio file.

Parameters
infilePointer to the input FILE stream.
infoPointer to the gdJpegInfo structure to populate with header information.
Returns
Returns 1 on success, 0 on failure.

◆ gdJpegGetInfoCtx()

int gdJpegGetInfoCtx ( gdIOCtxPtr  infile,
gdJpegInfo info 
)

Read JPEG header information from a gdIOCtx.

Parameters
infilePointer to the gdIOCtx input context.
infoPointer to the gdJpegInfo structure to populate with header information.
Returns
Returns 1 on success, 0 on failure.

◆ gdJpegGetInfoPtr()

int gdJpegGetInfoPtr ( int  size,
const void *  data,
gdJpegInfo info 
)

Read JPEG header information from a memory buffer.

Parameters
sizeSize of the memory buffer.
dataPointer to the memory buffer containing JPEG data.
infoPointer to the gdJpegInfo structure to populate with header information.
Returns
Returns 1 on success, 0 on failure.

◆ gdJpegGetVersionString()

const char * gdJpegGetVersionString ( )

Create an image from a JPEG memory buffer and collect metadata.

Create a JPEG image from memory using read options and collect metadata.

Parameters
sizeThe size of the JPEG memory buffer.
dataPointer to the JPEG memory buffer.
metadataPointer to a gdImageMetadata structure to collect metadata.
Returns
Returns a gdImagePtr on success, or NULL on failure.

Create an image from a JPEG memory buffer with warning control and metadata collection.

Parameters
sizeThe size of the JPEG memory buffer.
dataPointer to the JPEG memory buffer.
ignore_warningNon-zero to suppress recoverable JPEG warnings.
metadataPointer to a gdImageMetadata structure to collect metadata.
Returns
Returns a gdImagePtr on success, or NULL on failure.

Return a string describing the linked JPEG library version.

Returns
Returns a string describing the linked JPEG library version.

◆ gdJpegInfoInit()

void gdJpegInfoInit ( gdJpegInfo info)

Initialize a gdJpegInfo structure with default values.

Parameters
infoPointer to the gdJpegInfo structure to initialize.

◆ gdJpegReadOptionsInit()

void gdJpegReadOptionsInit ( gdJpegReadOptions options)

Initialize JPEG read options with default values.

Parameters
optionsPointer to the gdJpegReadOptions structure to initialize.

◆ gdJpegWriteOptionsInit()

void gdJpegWriteOptionsInit ( gdJpegWriteOptions options)

Initialize JPEG write options with default values.

Parameters
optionsPointer to the gdJpegWriteOptions structure to initialize.