jpeg: libiptcdata Reference Manual

## jpeg jpeg |

## Functions

int | iptc_jpeg_read_ps3 ()
int | iptc_jpeg_ps3_find_iptc ()
int | iptc_jpeg_ps3_save_iptc ()
int | iptc_jpeg_save_with_ps3 ()

## Description

## Functions

### iptc_jpeg_read_ps3 ()

    int
    iptc_jpeg_read_ps3 (FILE *infile,
                        unsigned char *buf,
                        unsigned int size);

Scans the headers of a JPEG file looking for a "Photoshop 3.0" header, and if found, stores the raw contents of this header in the `buf` buffer. The Photoshop 3.0 header is a series of records found in the APP13 section of a JPEG file. If a JPEG file contains IPTC metadata, the metadata is stored in one of the Photoshop 3.0 records.

#### Parameters

infile | an open JPEG file with the current position set to the start of the file |
buf | an output buffer to store the Photoshop 3.0 data |
size | the size of the output buffer |

#### Returns

the number of bytes stored on success, 0 if the PS3 header was not found, or -1 if an error occurred.

### iptc_jpeg_ps3_find_iptc ()

    int
    iptc_jpeg_ps3_find_iptc (const unsigned char *ps3,
                             unsigned int ps3_size,
                             unsigned int *iptc_len);

Parses a "Photoshop 3.0" header in search of IPTC metadata.

#### Parameters

ps3 | the data of a Photoshop 3.0 header to search |
ps3_size | size in bytes of `ps3` |
iptc_len | output parameter, the size in bytes of any found IPTC data |

#### Returns

the offset in bytes from the start of `ps3` where a block of IPTC metadata begins, 0 if no IPTC metadata was found, -1 on error.

### iptc_jpeg_ps3_save_iptc ()

    int
    iptc_jpeg_ps3_save_iptc (const unsigned char *ps3,
                             unsigned int ps3_size,
                             const unsigned char *iptc,
                             unsigned int iptc_size,
                             unsigned char *buf,
                             unsigned int size);

Takes a Photoshop 3.0 header, `ps3` , removes any existing IPTC data inside that header, and inserts the new IPTC data from `iptc` . Any other non-IPTC portions of `ps3` are left unmodified. If `ps3` is NULL, a blank PS3 header is created. If `iptc` is NULL, the output PS3 header will contain no IPTC data, even if `ps3` originally contained some.

#### Parameters

ps3 | a template PS3 header in which to insert the new iptc data. Any non-IPTC data in this template will be preserved in the output Photoshop 3.0 header. If NULL, a PS3 header will be generated from scratch. |
ps3_size | size in bytes of `ps3` |
iptc | the IPTC bytestream to be encapsulated in the PS3 output. The IPTC bytestream can be generated with `iptc_data_save()`. If NULL, the output will still be a valid PS3 header, but without any contained IPTC data. |
iptc_size | size in bytes of `iptc` |
buf | output buffer for the generated PS3 header |
size | size in bytes of `buf` |

#### Returns

the number of bytes written to `buf` ; -1 on error.

### iptc_jpeg_save_with_ps3 ()

    int
    iptc_jpeg_save_with_ps3 (FILE *infile,
                             FILE *outfile,
                             const unsigned char *ps3,
                             unsigned int ps3_size);

Takes an existing JPEG file, `infile` , removes any existing Photoshop 3.0 header from it, and adds a new PS3 header, writing the output to `outfile` . `infile` must be open for reading and is expected to point to the beginning of the JPEG file, which should be different from `outfile` , which must be open for writing. If `ps3` is NULL, the output will contain no PS3 header. PS3 headers reside in the APP13 section of the JPEG file, which is created if necessary. All other headers and data will be copied directly from `infile` without modification.

#### Parameters

infile | the file stream from which the image data is copied |
outfile | the output file stream |
ps3 | the Photoshop 3.0 header to add to the output file |
ps3_size | size in bytes of `ps3` |

#### Returns

0 on success, -1 on error. Note that even in error, some data may have been written to `outfile` , and its contents should be considered undefined.

## Types and Values