WebP (.webp)
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
Import Options
- Import options include:
-
ImageResolution Automatic resolution values for import "ImageTopOrientation" Automatic orientation of the image as stored in the file IncludeMetaInformation Automatic metadata types to import and export RasterSize Automatic dimensions of the image - Possible settings for "ImageTopOrientation" are Automatic, Top, Bottom, Left or Right.
Export Options
- Export to WebP has the same options as Rasterize, with the following additions and changes:
-
CompressionLevel 0 compression level, given as a number between 0 and 1 "ImageTopOrientation" Automatic orientation of the image as stored in the file IncludeMetaInformation Automatic metadata types to import and export RasterSize Automatic dimensions of the image - Export options for animated WebPs:
-
AnimationRepetitions Infinity how many times the animation plays before stopping "DisplayDurations" Automatic display duration for each frame in seconds - "DisplayDurations"->{d1,d2,…} specifies the display durations for each frame in an animated WebP.
Examples
open all close allBasic Examples (4)
Import["ExampleData/flowers.webp"]Import["ExampleData/flowers.webp", "Summary"]Import["http://exampledata.wolfram.com/sample.webp"]Export["image.webp", [image]]Scope (8)
Import (2)
Import["ExampleData/flowers.webp"]Import["ExampleData/flowers.webp", "Summary"]Import["http://exampledata.wolfram.com/sample.webp"]Import["http://exampledata.wolfram.com/sample.webp", "Summary"]Summary of frames in an animated WebP:
Import["http://exampledata.wolfram.com/sample.webp", "SummarySlideView"]Export (6)
Export["image.webp", [image]]Export["plot.webp", [image]]Export an arbitrary expression that gets rasterized:
Export["expr.webp", Nest[Subsuperscript[#, #, #]&, o, 4]];Import["expr.webp"]Create an animated WebP file from a list of images:
Export["animated.webp", {[image], [image], [image], [image], [image]}]Create an animated WebP file from an AnimatedImage object:
anim = AnimatedImage["ExampleData/pearls.png"];Export["animated.webp", anim]Create an animated WebP from a Manipulate:
m = Manipulate[Blur[[image], r], {r, 1, 10, 1}]Export["blur.webp", %]Read the number of exported frames:
Import["blur.webp", "ImageCount"]Note that duplicate frames are stored as one and the display durations are adjusted accordingly:
Import["blur.webp", "DisplayDurations"]Import Elements (33)
Available Elements (1)
Data Representation (12)
"AnimatedImage" (1)
Import as an AnimatedImage object:
Import["http://exampledata.wolfram.com/sample.webp", "AnimatedImage"]Head[%]"Data" (1)
"Graphics" (1)
Import as a Graphics object:
Import["ExampleData/flowers.webp", "Graphics"]Head[%]"GraphicsList" (2)
Get the data as a list of Graphics objects:
Import["http://exampledata.wolfram.com/sample.webp", "GraphicsList"][[1 ;; 3]]Import["http://exampledata.wolfram.com/sample.webp", {"GraphicsList", 1 ;; 3}]"Image" (1)
Import as an Image object:
Import["ExampleData/flowers.webp", "Image"]Head[%]This is the default import element for a single-frame WebP:
Import["ExampleData/flowers.webp"]//Head"ImageList" (3)
Get the data as a list of Image objects:
Import["http://exampledata.wolfram.com/sample.webp", "ImageList"]This is the default import element for animated WebP:
Import["http://exampledata.wolfram.com/sample.webp"]Import["http://exampledata.wolfram.com/sample.webp", {"ImageList", 1 ;; 3}]"Thumbnail" (1)
"ThumbnailList" (2)
Metadata (20)
"AnimationRepetitions" (1)
"BitDepth" (1)
"CameraTopOrientation" (1)
"Channels" (1)
"ColorSpace" (1)
Get the color encoding used on export:
Import["ExampleData/flowers.webp", "ColorSpace"]Use ImageColorSpace to get the color space of an imported image:
Import["ExampleData/flowers.webp"]//ImageColorSpace"DateTime" (1)
"Exif" (3)
Import["ExampleData/flowers.webp", "Exif"]Extract an individual tag from the association:
Import["ExampleData/flowers.webp", "Exif"]["Image", "FNumber"]Individual Exif tags can also be imported directly:
Import["ExampleData/flowers.webp", "FNumber"]Some Exif tags are processed to give more detailed information:
Import["ExampleData/flowers.webp", "FlashInfo"]Compare with the raw "Flash" tag:
Import["ExampleData/flowers.webp", "RawExif"]["Image", "Flash"]"DisplayDurations" (1)
"FlashUsed" (1)
Import a tag that shows whether the flash fired:
Import["ExampleData/flowers.webp", "FlashUsed"]"FlashUsed" is a subelement of the "FlashInfo" element:
Import["ExampleData/flowers.webp", "Exif"]["Image", "FlashInfo"]Extract "FlashUsed" from the full "Exif":
Import["ExampleData/flowers.webp", "Exif"]["Image", "FlashInfo", "FlashUsed"]"ImageCount" (1)
"MetaInformation" (1)
"RasterSize" (1)
Get the dimensions of the image stored in the file:
Import["ExampleData/flowers.webp", "RasterSize"]Use ImageDimensions on an imported image gives the same result:
Import["ExampleData/flowers.webp"]//ImageDimensions"RawExif" (1)
Import["ExampleData/flowers.webp", "RawExif"]Raw Exif tags return the actual values stored in the file:
Import["ExampleData/flowers.webp", "RawExif"]["Image", "FocalLength"]When importing "Exif", most tags are processed:
Import["ExampleData/flowers.webp", "Exif"]["Image", "FocalLength"]"RawXMP" (1)
"RedEyeCorrection" (1)
"Summary" (1)
"SummarySlideView" (1)
Import Options (6)
ImageResolution (1)
By default, the image resolution is extracted from the file:
Options[Import["ExampleData/flowers.webp"], ImageResolution]Specify the resolution of the imported image:
Options[Import["ExampleData/flowers.webp", ImageResolution -> 144], ImageResolution]Specify different resolutions in
and
directions:
Options[Import["ExampleData/flowers.webp", ImageResolution -> {72, 144}], ImageResolution]"ImageTopOrientation" (1)
By default, images are imported with the top orientation:
Import["ExampleData/flowers.webp"]Specify the side that is supposed to be on the top:
Import["ExampleData/flowers.webp", "ImageTopOrientation" -> Left]The correct orientation can also be achieved by rotating the image to be upright:
ImageRotate[Import["ExampleData/flowers.webp", "ImageTopOrientation" -> Left], Top -> Left]IncludeMetaInformation (3)
By default, all available metadata is imported:
Options[Import["ExampleData/flowers.webp"], MetaInformation]//ShortPossible classes of metadata for JPEG files are "Exif" and "XMP":
Options[Import["ExampleData/flowers.webp"], MetaInformation][[1, 2]]//KeysImport the image with no metadata:
Options[Import["ExampleData/flowers.webp", IncludeMetaInformation -> None], MetaInformation]Import the image with "XMP" metadata only:
Options[Import["ExampleData/flowers.webp", IncludeMetaInformation -> {"XMP"}], MetaInformation]//ShortRasterSize (1)
By default, images are imported in their full resolution:
Import["ExampleData/flowers.webp"]ImageDimensions[%]Specify the raster size of the imported WebP image:
Import["ExampleData/flowers.webp", RasterSize -> 50]ImageDimensions[%]Export Options (7)
AnimationRepetitions (1)
By default, animation is set to be repeated infinitely:
anim = AnimatedImage[{[image], [image], [image], [image], [image]}];Export["animated.webp", anim]Import["animated.webp", "AnimationRepetitions"]Specify the number of repetitions:
Export["animated.webp", anim, AnimationRepetitions -> 2]Import["animated.webp", "AnimationRepetitions"]CompressionLevel (1)
By default, no compression is used during export:
i = [image];Export["image.webp", i]ImageDifference[i, Import["image.webp"]]//MinMaxA larger CompressionLevel can decrease the file size:
Export["image2.webp", i, CompressionLevel -> 1]FileByteCount /@ {"image.webp", "image2.webp"}Notice the decreased quality of the exported image:
Import["image2.webp"]Compare the change in file size and quality difference using different compression levels:
t = Table[{FileSize[Export["file.webp", i, CompressionLevel -> level]], ImageDistance[Import["file.webp"], i]}, {level, 0, 1, .05}];ListLinePlot[Transpose[t], ...]"DisplayDurations" (2)
By default, a fixed duration is used for all frames:
anim = ConstantImage[#, 50]& /@ {Red, Green, Blue, Black}Export["animated.webp", anim]Import["animated.webp", "DisplayDurations"]Specify the duration of each frame:
Export["animated.webp", anim, "DisplayDurations" -> {.1, .2, .3, .4}]Import["animated.webp", "DisplayDurations"]Duplicate frames are combined and the frame duration is adjusted accordingly:
anim = ConstantImage[#, 50]& /@ {Red, Green, Blue, Black, Black, Black}Export["animated.webp", anim]Import["animated.webp", "DisplayDurations"]Import["animated.webp", "ImageCount"]"ImageTopOrientation" (1)
By default, the upright image is exported using "ImageTopOrientation"->Top:
i = [image];Export["test.webp", i]Import[%]Specify top orientation of the exported image:
Export["test.webp", i, "ImageTopOrientation" -> Left]Import[%]IncludeMetaInformation (1)
RasterSize (1)
By default, the image is exported in the full resolution:
i = [image];ImageDimensions[i]Export["test.webp", i]Import[%, "RasterSize"]Specify the raster size of the exported image:
Export["test.webp", i, RasterSize -> 47]Import[%, "RasterSize"]Tech Notes
Related Guides
History
Introduced in 2014 (10.0) | Updated in 2016 (11.0) ▪ 2020 (12.1) ▪ 2021 (12.3) ▪ 2021 (13.0) ▪ 2022 (13.2) ▪ 2026 (15.0)