JPEG (.jpg, .jpeg)
Background & Context

-
- MIME type: image/jpeg
- JPEG raster image and compression format.
- Commonly used for photographic images by digital cameras and on the web.
- JPEG is an acronym for Joint Photographic Experts Group.
- Supports Grayscale, RGB, and CMYK color spaces.
- Stores images as bitmaps at a resolution of 8 bits per color channel.
- Binary format.
- Uses a lossy compression method based on an 8×8 block-sized discrete cosine transform.
- Supports different compression levels.
Import & Export

- Import["file.jpg"] imports a JPEG file, returning an image.
- Import["file.jpg",elem] imports the specified element from a JPEG file.
- The import format can be specified with Import["file","JPEG"] or Import["file",{"JPEG",elem,…}].
- Export["file.jpg",expr] exports an image, graphics, or any other expression as an image to a JPEG file.
- Image objects are by default exported at their full raster size. Graphics and other arbitrary expressions are exported using the same raster size as their displayed form.
- See the following reference pages for full general information:
-
Import, Export import from or export to a file CloudImport, CloudExport import from or export to a cloud object ImportString, ExportString import from or export to a string ImportByteArray, ExportByteArray import from or export to a byte array
Notebook Interface

- In the notebook front end, Insert ▶ Picture and the Open menu allow the import of a JPEG file into a cell.
- Save Selection As exports the selected part of a notebook as a JPEG file.
Import Elements




- General Import elements:
-
"Elements" list of elements and options available in this file "Summary" summary of the file "Rules" list of rules for all available elements - Data representation elements:
-
"ColorMap" color reduction palette "Data" array of pixel values "Graphics" raster image, given as a Graphics object "Image" raster image, given as an Image object "RawData" array of color map indices "Thumbnail" thumbnail of the first image - Import and Export by default use the "Image" element for the JPEG format.
- Subelements for partial data import for any element elem can take row and column specifications in the form {elem,rows,cols}, where rows and cols can be any of the following:
-
n nth row or column -n counts from the end n;;m from n through m n;;m;;s from n through m with steps of s {n1,n2,…} specific rows or columns ni - Advanced Import elements:
-
"BitDepth" bits used to represent each color channel in the file "CameraTopOrientation" orientation of the camera when the picture was taken "Channels" - the number of color channels used in the file
"ColorProfileData" embedded color profile, given as a ColorProfileData object "ColorSpace" color encoding used in the file "FlashUsed" - whether the flash was fired
"GeoPosition" latitude and longitude represented as a GeoPosition object "GPSDateTime" - image creation date and time registered by GPS
"RasterSize" raster dimensions "RedEyeCorrection" whether a red-eye correction was performed - Metadata elements:
-
"Exif" formatted Exif (Exchange image file format) "IPTC" formatted IPTC (International Press Telecommunications Council) "XMP" formatted XMP (Extensible metadata platform) "MetaInformation" combination of all formatted metadata present in the file - Raw metadata, as stored in the file, can be imported using "RawExif", "RawXMP" and "RawIPTC" elements which are returned in an association.
- All Exif and IPTC tags can be imported individually. Common tags include:
-
"ApertureValue" lens aperture "Artist" photographer or image creator "DateTime" image creation date and time "ExposureTime" exposure time, given in seconds "FlashInfo" - flash information: flash fired, red-eye correction, etc.
"FNumber" F number "FocalLength" actual focal length of the lens, given in millimeters "GPSAltitude" altitude of the GPS position "GPSLatitude" latitude of the GPS position "GPSLongitude" longitude of the GPS position "Make" manufacturer of the recording equipment "Model" model name or model number of the equipment "Software" name and version of the software or firmware of the camera or image input device used to generate the image
Options

- Import and Export options:
-
ImageResolution Automatic resolution values for import and export "ImageTopOrientation" Automatic orientation of the image as stored in the file IncludeMetaInformation All metadata types to import and export RasterSize Automatic dimensions of the image - Export options:
-
ColorSpace "RGB" color space to be used in the file CompressionLevel 0.25 sets the JPEG compression parameter ImageFormattingWidth $ImageFormattingWidth target width when formatting an object "Progressive" False whether to store the image in a way that allows progressive display while the file is being loaded "Smoothing" 0 the JPEG smoothing parameters, given as a number in the range 0 (no smoothing) to 1 - Supported ColorSpace settings are: "Grayscale", "RGB", and "CMYK". Using ColorSpace->Automatic, Export attempts to create a JPEG file with the same color space.
- The value of CompressionLevel can be in the range from 0 to 1, with larger values resulting in smaller file sizes but lower-quality encodings.
Examples
open allclose allBasic Examples (3)Summary of the most common use cases
Scope (3)Survey of the scope of standard use cases
Import the image as a graphics:

https://wolfram.com/xid/0cvl7wm-1i8t43


https://wolfram.com/xid/0cvl7wm-kirbjm


https://wolfram.com/xid/0cvl7wm-43xk5z


https://wolfram.com/xid/0cvl7wm-dx7gqu

Import multiple metadata elements:

https://wolfram.com/xid/0cvl7wm-o71gkw

Import Elements (35)
Available Elements (4)

https://wolfram.com/xid/0cvl7wm-1g2ndh

List of available Exif elements:

https://wolfram.com/xid/0cvl7wm-e619fh

List of available IPTC elements:

https://wolfram.com/xid/0cvl7wm-txorq8

Get image-related information as list of rules:

https://wolfram.com/xid/0cvl7wm-myzd73

Data Representation (8)
"ColorMap" (2)
Get the color-reduction palette created on import:

https://wolfram.com/xid/0cvl7wm-cy3ssw

Visualize the color-reduction palette:

https://wolfram.com/xid/0cvl7wm-0vipsx

Apply the color map to the raw data to create the stored image:

https://wolfram.com/xid/0cvl7wm-fdn6ld

https://wolfram.com/xid/0cvl7wm-qo9gx8

"Data" (1)
"Graphics" (1)
Import as a Graphics object:

https://wolfram.com/xid/0cvl7wm-oxk5kn


https://wolfram.com/xid/0cvl7wm-oxk2tw

"Image" (2)
Import as an Image object:

https://wolfram.com/xid/0cvl7wm-vtuh6c


https://wolfram.com/xid/0cvl7wm-1f07e2

This is the default import element for JPEG:

https://wolfram.com/xid/0cvl7wm-s0naad

Import only the specified rows:

https://wolfram.com/xid/0cvl7wm-yia4mv

Import specified rows and columns:

https://wolfram.com/xid/0cvl7wm-26vfhv

Metadata (23)
"BitDepth" (1)
"CameraTopOrientation" (2)
Get the camera orientation at the capture time:

https://wolfram.com/xid/0cvl7wm-r9gbrs

The image is auto-rotated on Import:

https://wolfram.com/xid/0cvl7wm-g3mrer

An auto-rotated image has an updated Exif tag:

https://wolfram.com/xid/0cvl7wm-ob591l

Avoid auto-rotation by setting the "ImageTopOrientation" option:

https://wolfram.com/xid/0cvl7wm-wlc57a

"Channels" (1)
"ColorProfileData" (1)
Get the embedded color profile, given as a ColorProfileData object:

https://wolfram.com/xid/0cvl7wm-1xdwml

The color profile is stored in the ColorSpace option of the imported image:

https://wolfram.com/xid/0cvl7wm-mpv214

"ColorSpace" (1)
Get the color encoding used on export:

https://wolfram.com/xid/0cvl7wm-wb968h

Use ImageColorSpace to get the color space of an imported image:

https://wolfram.com/xid/0cvl7wm-ca8qqr

"DateTime" (1)
"Exif" (3)

https://wolfram.com/xid/0cvl7wm-f0526s

Extract an individual tag from the association:

https://wolfram.com/xid/0cvl7wm-omm9zg

Individual Exif tags can also be imported directly:

https://wolfram.com/xid/0cvl7wm-55ozsh

Some Exif tags are processed to give more detailed information:

https://wolfram.com/xid/0cvl7wm-xpmhcz

Compare with the raw "FlashInfo" tag:

https://wolfram.com/xid/0cvl7wm-3h2d51

"FlashUsed" (1)
Import a tag that shows whether the flash fired:

https://wolfram.com/xid/0cvl7wm-xabiy

"FlashUsed" is a subelement of the "FlashInfo" element:

https://wolfram.com/xid/0cvl7wm-v4pueu

Extract "FlashUsed" from the full "Exif":

https://wolfram.com/xid/0cvl7wm-h0cksj

"GeoPosition" (2)

https://wolfram.com/xid/0cvl7wm-e0aa3z


https://wolfram.com/xid/0cvl7wm-iusskr

Use the image thumbnail as the marker:

https://wolfram.com/xid/0cvl7wm-g2wkji

The image geo position may be unavailable:

https://wolfram.com/xid/0cvl7wm-pxb14l

"GPSDateTime" (1)
"MetaInformation" (1)
"RasterSize" (1)
Get the dimensions of the image stored in the file:

https://wolfram.com/xid/0cvl7wm-ma62cc

Using ImageDimensions on an imported image gives the same result:

https://wolfram.com/xid/0cvl7wm-hjusgl

"RawExif" (1)

https://wolfram.com/xid/0cvl7wm-mf9zrs

When importing processed Exif data, missing tags are removed:

https://wolfram.com/xid/0cvl7wm-181rsc

Raw Exif tags return the actual values stored in the file:

https://wolfram.com/xid/0cvl7wm-dj1jcj

When importing "Exif", most tags are processed:

https://wolfram.com/xid/0cvl7wm-k1llg3

"RawIPTC" (1)
"RawXMP" (1)
"RedEyeCorrection" (1)
Import Options (6)
ImageResolution (1)
By default, the image resolution is extracted from the file:

https://wolfram.com/xid/0cvl7wm-kux3uu

Specify the resolution of the imported image:

https://wolfram.com/xid/0cvl7wm-f98eh7

Specify different resolutions in and
directions:

https://wolfram.com/xid/0cvl7wm-rc4e7v

"ImageTopOrientation" (1)
By default, images are imported with the native orientation stored in the file:

https://wolfram.com/xid/0cvl7wm-qpx1rr

Specify the side that is supposed to be on the top:

https://wolfram.com/xid/0cvl7wm-f2hain

The correct orientation can also be achieved by rotating the image to be upright:

https://wolfram.com/xid/0cvl7wm-y94tbh

IncludeMetaInformation (3)
By default, all available metadata is imported:

https://wolfram.com/xid/0cvl7wm-oy06er

Possible classes of metadata for JPEG files are "Exif", "IPTC", and "XMP":

https://wolfram.com/xid/0cvl7wm-k3r4ps

Import the image with no metadata:

https://wolfram.com/xid/0cvl7wm-inmgwp

Import the image with "XMP" metadata only:

https://wolfram.com/xid/0cvl7wm-fpx9h0

RasterSize (1)
Export Options (7)
ColorSpace (1)
By default, the native color space of the image is used for export:

https://wolfram.com/xid/0cvl7wm-umqnom

https://wolfram.com/xid/0cvl7wm-cd7oot


https://wolfram.com/xid/0cvl7wm-dky0tw


https://wolfram.com/xid/0cvl7wm-zxgis3


https://wolfram.com/xid/0cvl7wm-6mo35w

CompressionLevel (2)
By default, an automatic compression is used:

https://wolfram.com/xid/0cvl7wm-cp4z8j

https://wolfram.com/xid/0cvl7wm-m3pjgi


https://wolfram.com/xid/0cvl7wm-spt1wl


https://wolfram.com/xid/0cvl7wm-4bsrso

Compare the byte count for different compression levels:

https://wolfram.com/xid/0cvl7wm-gg1mb9

ImageResolution (1)
By default, the original image resolution is used during export:

https://wolfram.com/xid/0cvl7wm-kai93b


https://wolfram.com/xid/0cvl7wm-54zrpd


https://wolfram.com/xid/0cvl7wm-7i0h4k


https://wolfram.com/xid/0cvl7wm-sykeih

Specify the resolution of the exported image:

https://wolfram.com/xid/0cvl7wm-7ugd7m


https://wolfram.com/xid/0cvl7wm-dnh0n6

"ImageTopOrientation" (1)
By default, the upright image is exported using "ImageTopOrientation"->Top:

https://wolfram.com/xid/0cvl7wm-kje3az

https://wolfram.com/xid/0cvl7wm-9ogv7d


https://wolfram.com/xid/0cvl7wm-oj40fq


https://wolfram.com/xid/0cvl7wm-i70bei


https://wolfram.com/xid/0cvl7wm-olrxst

Import using the original orientation:

https://wolfram.com/xid/0cvl7wm-s4jg2y

IncludeMetaInformation (1)
By default, all existing meta-information is exported:

https://wolfram.com/xid/0cvl7wm-il1ikv

https://wolfram.com/xid/0cvl7wm-d26knl


https://wolfram.com/xid/0cvl7wm-bohxwt

Specify the metadata to include:

https://wolfram.com/xid/0cvl7wm-lyrps1


https://wolfram.com/xid/0cvl7wm-b0836r


https://wolfram.com/xid/0cvl7wm-byetx0


https://wolfram.com/xid/0cvl7wm-no6mmq

RasterSize (1)
By default, the image is exported in the full resolution:

https://wolfram.com/xid/0cvl7wm-lszysm

https://wolfram.com/xid/0cvl7wm-bhjnpf


https://wolfram.com/xid/0cvl7wm-t9ntr8


https://wolfram.com/xid/0cvl7wm-7p8hv4

Specify the raster size of the exported image:

https://wolfram.com/xid/0cvl7wm-3ie1wu


https://wolfram.com/xid/0cvl7wm-ss5jdi
