Previous section To contents Next section

12.24 Image.JPEG

DESCRIPTION

NOTE
This module uses libjpeg, a software from Independent JPEG Group.

METHOD
Image.JPEG._decode,
Image.JPEG.decode,
Image.JPEG.decode_header

SYNTAX
object decode(string data)
object decode(string data,  mapping options)
mapping _decode(string data)
mapping _decode(string data,  mapping options)
mapping decode_header(string data)

DESCRIPTION
Decodes a JPEG image. The simple decode function simply gives the image object, the other functions gives a mapping of information (see below)

The options argument may be a mapping containing zero or more encoding options:

advanced options:
"block_smoothing":0|1
Do interblock smoothing. Default is on (1).
"fancy_upsampling":0|1
Do fancy upsampling of chroma components.
Default is on (1).
"method":JPEG.IFAST|JPEG.ISLOW|JPEG.FLOAT|JPEG.DEFAULT|JPEG.FASTEST
DCT method to use.
DEFAULT and FASTEST is from the jpeg library,
probably ISLOW and IFAST respective.

wizard options: "scale_num":1.. "scale_denom":1.. Rescale the image when read from JPEG data. My (Mirar) version (6a) of jpeglib can only handle 1/1, 1/2, 1/4 and 1/8.

_decode and decode_header gives a mapping as result, with this content:

"xsize":int
"ysize":int
size of image
"xdpi":float
"ydpi":float
image dpi, if known
"type":"image/jpeg"
file type information as MIME type

JPEG specific: "num_compontents":int number of channels in JPEG image "color_space":"GRAYSCALE"|"RGB"|"YUV"|"CMYK"|"YCCK"|"UNKNOWN" color space of JPEG image "density_unit":int "x_density":int "y_density":int density of image; unit is 1:dpi 2:dpcm 0:no units "adobe_marker":0|1 if the file has an adobe marker

NOTE
Please read some about JPEG files.

METHOD
Image.JPEG.encode

SYNTAX
string encode(object image)
string encode(object image,  mapping options)

DESCRIPTION
Encodes a JPEG image.

The options argument may be a mapping containing zero or more encoding options:

normal options:
"quality":0..100
Set quality of result. Default is 75.
"optimize":0|1
Optimize Huffman table. Default is on (1) for
images smaller than 50kpixels.
"progressive":0|1
Make a progressive JPEG. Default is off.

advanced options: "smooth":1..100 Smooth input. Value is strength. "method":JPEG.IFAST|JPEG.ISLOW|JPEG.FLOAT|JPEG.DEFAULT|JPEG.FASTEST DCT method to use. DEFAULT and FASTEST is from the jpeg library, probably ISLOW and IFAST respective.

"density_unit":int "x_density":int "y_density":int density of image; unit is 1:dpi 2:dpcm 0:no units

wizard options: "baseline":0|1 Force baseline output. Useful for quality<25. Default is on for quality<25. "quant_tables":mapping(int,array(array(int))) Tune quantisation tables manually.

NOTE
Please read some about JPEG files. A quality setting of 100 does not mean the result is lossless.

Previous section To contents Next section