Convert JPG, PNG, and Animated GIF to WEBP

By  on  

New image formats like WEP and MOZJPEG will be a major boost to load time on the web.  The majority of page load and render time is usually attributed to unoptimized images, so these new formats will make both mobile and desktop load times faster.  I've taught you how to detect WEBP support but we've not explored how to create WEBP images; let's have a look at how easy it is to convert JPG, PNG, and even animated GIF to WEBP.

Convert JPG and PNG to WEBP

My favorite open source image manipulation library, ImageMagick, doesn't have the capability to convert images to WEBP out of the box -- you'll receive an ugly error if you don't first install webp via a utility like homebrew:

brew install webp

Once webp is available, you can use ImageMagick to do the conversion:

convert logo.png logo.webp

In most cases the WEBP image, which is only available in Chrome at the time of publishing, will be significantly smaller than the original image.

Convert Animated GIF to WEBP

The webp library doesn't have the capability to convert animated GIF images to WEBP.  You'll need to download gif2webp from Google.  With gif2webp available, you can convert your animated GIF image to WEBP:

gif2webp animation.gif -o animation.webp

gif2webp provides numerous options for output modification like quality, multi-threading encoding, etc.

Imagine the boost in your site load time if you created and served WEBP images where they're supported.  Faster sites means more conversions and better user experience.  Make it happen!

Recent Features

  • By
    Designing for Simplicity

    Before we get started, it's worth me spending a brief moment introducing myself to you. My name is Mark (or @integralist if Twitter happens to be your communication tool of choice) and I currently work for BBC News in London England as a principal engineer/tech...

  • By
    5 HTML5 APIs You Didn’t Know Existed

    When you say or read "HTML5", you half expect exotic dancers and unicorns to walk into the room to the tune of "I'm Sexy and I Know It."  Can you blame us though?  We watched the fundamental APIs stagnate for so long that a basic feature...

Incredible Demos

  • By
    Multiple Backgrounds with CSS

    Anyone that's been in the web development industry for 5+ years knows that there are certain features that we should have had several years ago. One of those features is the HTML5 placeholder; we used JavaScript shims for a decade before placeholder came...

  • By
    Save Web Form Content Using Control + S

    We've all used word processing applications like Microsoft Word and if there's one thing they've taught you it's that you need to save every few seconds in anticipation of the inevitable crash. WordPress has mimicked this functionality within their WYSIWYG editor and I use it...

Discussion

  1. pascal massimino

    Note: one important gif2webp option is -min_size. This one can be used to minimize the file size.

    This is not the default because gif2web favors minimizing the playback smoothness instead (by inserting larger keyframes at regular interval).

    skal/

  2. WEBP is something which every body was waiting for, as other images took a long time to load, so this innovation is more than welcome and many thanks for sharing us with the method to convert other image formats into webp.

  3. emmze

    Since support for webp in browsers is limited right now, is there any big advantage to using webp instead of svgs? I tried some tests just now, converting some variously sized png images to both webp and svg. The resulting size was about the same (webp usually slightly smaller) but svg has much better browser support, so why not just use svgs?

  4. You don’t even need webp to shrink gifs for the web. Simply use mp4s instead if you want 100% browser-support. That often saves around 90% of file-size.

    Then you can modify the tag to look and behave like a gif, too. Use the inline & autoplay attributes.

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!