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:
  • imagean Image expression
    graphicsrasterized graphics
    expran 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 reference pages for full general information on Import and Export.
  • ImportString and ExportString support the WebP format.

Import Elements

  • 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:
  • "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:
  • nnth frame
    -ncounts from the end
    n;;mfrom n through m
    n;;m;;sfrom 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
  • 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
    "ImageSize"raster dimensions
  • summary of the file
  • "SummarySlideView"slide view summary of all frames



open allclose all

Basic Examples  (4)

Import a WebP file:

Summary of an image:

Import a multi-frame WebP:

Export an image to WebP:

Scope  (8)

Import  (2)

Import a static WebP image:

Summary of a WebP image:

Import an animated WebP:

Summary of an animated WebP:

Summary of frames in an animated WebP:

Export  (6)

Export an image to WebP:

Export graphics to WebP:

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  (22)

Available Elements  (1)

List of available elements:

Data Representation  (12)

"AnimatedImage"  (1)

Import as an AnimatedImage object:

"Data"  (1)

Import the image data:

Construct images of the proper type:

"Graphics"  (1)

Import as a Graphics object:

"GraphicsList"  (2)

Get the data as a list of Graphics objects:

Specify the frames to import:

"Image"  (1)

Import as an Image object:

This is the default import element for a single-frame WebP:

"ImageList"  (3)

Get the data as a list of Image objects:

This is the default import element for animated WebP:

Specify the frames to import:

"Thumbnail"  (1)

Import thumbnail of an image:

Show the elements that can be imported from this file:

Get the "BitDepth" and "ImageSize" elements:

"ThumbnailList"  (2)

Import a list of thumbnails of a multi-framed image:

Specify the frames to import:

Metadata  (9)

"AnimationRepetitions"  (1)

Get the number of times the animation is expected to repeat:

"BitDepth"  (1)

Get the number of bits used for representing each color channel:

"Channels"  (1)

Get the color encoding used on export:

"ColorSpace"  (1)

Get the color encoding used on export:

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

"DisplayDurations"  (1)

Get the duration of each frame in the animations:

"ImageCount"  (1)

Get the number of frames:

"ImageSize"  (1)

Get the dimensions of the image stored in the file:

Use ImageDimensions on an imported image gives the same result:

"Summary"  (1)

Get the image summary:

"SummarySlideView"  (1)

Get the image frames' summary:

Import Options  (2)

ImageSize  (1)

By default, images are imported in their full resolution:

Specify the raster size of the imported WebP image:

"ImageTopOrientation"  (1)

By default, images are imported with the top orientation:

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

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

Export Options  (6)

AnimationRepetitions  (1)

By default, animation is set to be repeated infinitely:

Specify the number of repetitions:

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)

By default, a fixed duration is used for all frames:

Specify the duration of each frame:

Duplicate frames are combined and the frame duration is adjusted accordingly:

ImageSize  (1)

By default, the image is exported in the full resolution:

Specify the raster size of the exported image:

"ImageTopOrientation"  (1)

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

Specify the raster size of the exported image: