JPEG (.jpg, .jpeg)

  • Import and Export fully support the JPEG standard.
  • Import also supports parts of the Exif 2.2 metadata standard.

BackgroundBackground

    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 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 and ExportImport and Export

  • Import["file.jpg"] imports a JPEG file and returns an image.
  • Export["file.jpg",expr] exports an image, graphics, or any other expression as a raster image to JPEG.
  • When exporting Wolfram Language graphics or arbitrary expressions to JPEG, the resulting image has the same raster size as its displayed form.
  • Image objects are by default exported at their raster size.
  • Because JPEG is a raster image format, all fonts are rasterized on export.
  • Import["file.jpg",elem] imports the specified element from a JPEG file.
  • Import["file.jpg",{elem,suba,subb,}] imports a subelement.
  • Import["file.jpg",{{elem1,elem2,}}] imports multiple elements.
  • The import format can be specified with Import["file","JPEG"] or Import["file",{"JPEG",elem,}].
  • Export["file.jpg",expr,elem] creates a JPEG file by treating expr as specifying element elem.
  • Export["file.jpg",{expr1,expr2,},{{elem1,elem2,}}] treats each as specifying the corresponding .
  • Export["file.jpg",expr,opt1->val1,] exports expr with the specified option elements taken to have the specified values.
  • Export["file.jpg",{elem1->expr1,elem2->expr2,},"Rules"] uses rules to specify the elements to be exported.
  • See the reference pages for full general information on Import and Export.
  • ImportString and ExportString support the JPEG format.

Notebook InterfaceNotebook 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.

ElementsElements

  • General Import elements:
  • "Elements" list of elements and options available in this file
    "Rules"full list of rules for each element and option
    "Options"list of rules for options, properties, and settings
  • Data representation elements:
  • "ColorMap"color reduction palette created on import
    "Data"array of color values taken
    "Graphics"Graphics object representing an image
    "Image"raster image, given as an Image object
    "GrayLevels"array of normalized gray-level values
    "RGBColorArray"array of RGBColor objects
    "RawData"array of indexed colors
  • Import and Export by default use the element for the JPEG format.
  • Advanced Import elements:
  • "BitDepth"bits used to represent each color channel in the file
    "ColorProfileData"embedded color profile, given as a ColorProfileData object
    "ColorSpace"color encoding used in the file
    "ImageSize"raster dimensions
    "Exif"all Exif tags, given as a list of rules
  • Individual Exif tags (available for Import):
  • "FocalLength"focal length in millimeters
    "CameraTopOrientation"orientation of the camera when the picture was taken
    "Manufacturer"maker of the camera or input device
    "Model"model specification of the camera or input device
    "Exposure"photographic exposure time in seconds
    "Date"date and time the original picture was taken, given as a DateObject
    "Aperture"aperture setting at which the picture was taken, given in APEX units
    "ISOSpeed"ISO 12232 speed rating of the camera or input device
  • With the element, if Exif tags are available, they are embedded in the MetaInformation option of the imported Image object under the name . The embedded Exif tags are automatically exported when exporting as JPEG.

OptionsOptions

  • General option:
  • ImageSizeAutomaticoverall image size
  • Import and Export option:
  • "ImageTopOrientation"Toporientation of the image as stored in the file
  • Import options:
  • "TakeRows"{1,-1}rows to import
  • Export options:
  • "ColorSpace""RGB"color encoding to be used in the file
    "CompressionLevel"0.25sets the JPEG compression parameter
    "Progressive"Falsewhether to store the image in a way that allows progressive display while the file is being loaded
    "Smoothing"0the JPEG smoothing parameters, given as a number in the range 0 to 1
    ImageFormattingWidth$ImageFormattingWidthtarget width when formatting an object
  • With a setting "ColorSpace"->Automatic, the Wolfram Language attempts to create a JPEG file that has the same color space as the image to be exported. JPEG can store images with , , or color spaces.
  • When exporting a raster image to JPEG, no smoothing filter is applied by default.
  • can be set to values in the range from 0 to 1, with larger values resulting in smaller file sizes.
  • Since JPEG uses a lossy compression method, higher compression levels correspond to lower-quality encodings.

ExamplesExamplesopen allclose all

Basic Examples  (5)Basic Examples  (5)

Import a JPEG image as an image:

In[1]:=
Click for copyable input
Out[1]=

Get the pixel dimensions of this photo:

In[2]:=
Click for copyable input
Out[2]=

Show all Import elements available in the file:

In[1]:=
Click for copyable input
Out[1]=

Import metadata elements:

In[4]:=
Click for copyable input
Out[4]=

Read raw color data from the file and extract the first few pixels:

In[1]:=
Click for copyable input
Out[1]=

Import only the specified rows:

In[1]:=
Click for copyable input
Out[1]=

Export an RGB image to JPEG:

In[1]:=
Click for copyable input
Out[1]=

Export a CMYK image:

In[1]:=
Click for copyable input
Out[1]=
Introduced in 1999
(4.0)
| Updated in 2014
(10.0)