Poster of Linux kernelThe best gift for a Linux geek


Section: C Library Functions (3) Updated: 6 June 1994
Local index Up


im_jpeg2vips, im_vips2jpeg, im_vips2bufjpeg, im_vips2mimejpeg - convert JPEG images to and from VIPS format  


#include <vips/vips.h>

int im_jpeg2vips( char *filename, IMAGE *out )

int im_vips2jpeg( IMAGE *in, char *filename )

int im_vips2bufjpeg( IMAGE *in, IMAGE *base, char **obuf, int *olen )

int im_vips2mimejpeg( IMAGE *in )



im_jpeg2vips(3) reads the named jpeg file and writes it to the specified IMAGE. The entire image is read before returning. It can read most 8-bit JPEG images, including CMYK.

You can embed options in the filename. They have the form:


shrink-factor will shrink the image by that factor during read. Allowed values are 1, 2, 4 and 8. Shrinking during read is very much faster than decompressing the whole image and then shrinking. Example:


will return fred.jpg shrink by a factor of 8.

fail makes the JPEG reader fail on any warnings. This can be useful for detecting truncated files, for example. Normally reading these produces a warning, but no fatal error. Example:


will read fred.jpg, failing with a fatal error if the file has been truncated.

Any embedded ICC profiles are ignored: you always just get the RGB from the file. Instead, the embedded profile will be attached to the image as metadata. You need to use something like im_icc_import(3) to get CIE values from the file. Any EXIF data is also attached as VIPS metadata.

im_vips2jpeg(3) writes the IMAGE to filename in JPEG format. It uses the default settings of the IJG library.

A compression factor may be encoded in the filename: for example, "fred.jpg" will write with the default compression factor (75), "fred.jpg:25" will write with factor 25.

An ICC profile may also be specified. For example, "fred.jpg:,/home/john/srgb.icc" will embed the profile stored in the file "/home/john/srgb.icc" into the JPEG image. This does not affect the pixels which are written, just the way they are tagged. You can use the special string "none" to mean "don't attach a profile".

If no profile is specified in the save string and the VIPS header contains an ICC profile named IM_META_ICC_NAME ("icc-profile-data"), the profile from the VIPS header will be attached.

The image is automatically converted to RGB, Monochrome or CMYK before saving. Any metadata attached to the image is saved as EXIF, if possible.

im_vips2bufjpeg(3) returns the compressed image in a memory buffer. The buffer is allocated for you, local to IMAGE descriptor base. The size of the allocated buffer is returned in the olen parameter. You are responsible for freeing the buffer. The buffer is only allocated if the function returns successfully.

im_vips2mimejpeg(3) writes the image to stdout as a MIME image/jpeg type. It outputs Content-Length and Content-Type fields making the result suitable for sending to a web browser.







This document was created by man2html, using the manual pages.
Time: 21:48:27 GMT, April 16, 2011