WebP (.webp)
- Import and Export support the WebP format.
- Import and Export support Exif 2.3 and XMP metadata standards.
Background & Context
-
- Registered MIME type: image/webp
- WebP raster image format.
- Binary format.
- Stores both static and animated images.
- Stores color bitmaps at a resolution of 8 bits per channel.
- Supports alpha channels.
- Introduced in 2010 by Google to provide both lossy and lossless compression of images on the web.
Import & Export
- Import["file.webp"] imports a WebP file, returning a single Image object or a list of images.
- Import["file.webp",elem] imports the specified element from a WebP file.
- The import format can be specified with Import["file","WebP"] or Import["file",{"WebP",elem,…}].
- Export["file.webp",expr] exports the expression expr to WebP.
- The expression expr can be any of the following:
-
image an Image expression graphics rasterized graphics expr an arbitrary expression, rasterized {expr1,expr2,…} an animation of rasterized expressions AnimatedImage[…] an animation of an AnimatedImage frame Manipulate[…] an animation of a Manipulate expression - When exporting graphics or arbitrary expressions, the resulting image has the same raster size as its displayed form.
- Image objects are by default exported at their raster size.
- 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
Import Elements
- General Import elements:
-
"Elements" list of elements and options available in this file "Rules" list of rules for all available elements "Summary" - summary of the file
- Data representation elements:
-
"Data" array of color values "Graphics" Graphics object representing an image "Image" raster image, given as an Image object "Thumbnail" thumbnail of the first image - Data representation elements for animated WebP files:
-
"AnimatedImage" data returned as AnimatedImage object "GraphicsList" data returned as Graphics objects "ImageList" data returned as Image objects "ThumbnailList" data returned as thumbnails - Import by default uses the "Image" element for a static WebP and "ImageList" for an animated WebP.
- Import of an animated WebP with element "Image" gives the first frame of the animation.
- Subelements for data elements can be used with animated WebP files in the form {elem,frame}, where frame can be any of the following:
-
n nth frame -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 frames ni - Advanced Import elements:
-
"AnimationRepetitions" how many times the animation is played before stopping "BitDepth" bits used to represent each color channel "Channels" - the number of color channels
"ColorProfileData" embedded color profile, given as a ColorProfileData object "ColorSpace" color encoding used in the file "DisplayDurations" display durations of animation frames, given in seconds "ImageCount" number of frames "RasterSize" raster dimensions "Summary" - summary of the file
"SummarySlideView" slide view summary of all frames - Metadata class elements:
-
"Exif" formatted Exif (Exchange image file format) "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, returned as an association.
- All Exif tags can be imported individually. Common tags include:
-
"ApertureValue" lens aperture "DateTime" image creation date and time "ExposureTime" exposure time, given in seconds "FNumber" F number "FocalLength" actual focal length of the lens, given in millimeters "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 - Derived metadata elements:
-
"CameraTopOrientation" - orientation of the camera when the picture was taken
"FlashUsed" - whether the flash was fired
"GeoPosition" - latitude and longitude represented as GeoPosition object
"GPSDateTime" - image creation date and time registered by GPS
Options
- Import and Export option:
-
IncludeMetaInformation Automatic metadata types to import and export "ImageTopOrientation" Automatic orientation of the image as stored in the file RasterSize Automatic dimensions of the image - Export option:
-
CompressionLevel 0 compression level, given as a number between 0 and 1 - Export options for animated WebPs:
-
AnimationRepetitions Infinity how many times the animation plays before stopping "DisplayDurations" Automatic display duration for each frame in seconds
Examples
open allclose allBasic Examples (4)
Scope (8)
Import (2)
Export (6)
Export an arbitrary expression that gets rasterized:
Create an animated WebP file from a list of images:
Create an animated WebP file from an AnimatedImage object:
Create an animated WebP from a Manipulate:
Read the number of exported frames:
Note that duplicate frames are stored as one and the display durations are adjusted accordingly:
Import Elements (33)
Data Representation (12)
"AnimatedImage" (1)
Import as an AnimatedImage object:
"Graphics" (1)
Import as a Graphics object:
"GraphicsList" (2)
"Image" (1)
"ImageList" (3)
Get the data as a list of Image objects:
"Thumbnail" (1)
Metadata (20)
"ColorSpace" (1)
Get the color encoding used on export:
Use ImageColorSpace to get the color space of an imported image:
"Exif" (3)
"FlashUsed" (1)
"RasterSize" (1)
Get the dimensions of the image stored in the file:
Use ImageDimensions on an imported image gives the same result:
"RawExif" (1)
Import Options (5)
"ImageTopOrientation" (1)
IncludeMetaInformation (3)
Export Options (7)
AnimationRepetitions (1)
CompressionLevel (1)
By default, no compression is used during export:
A larger CompressionLevel can decrease the file size:
Notice the decreased quality of the exported image:
Compare the change in file size and quality difference using different compression levels:
"DisplayDurations" (2)
"ImageTopOrientation" (1)
By default, the upright image is exported using "ImageTopOrientation"->Top: