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
    CSS @supports

    Feature detection via JavaScript is a client side best practice and for all the right reasons, but unfortunately that same functionality hasn't been available within CSS.  What we end up doing is repeating the same properties multiple times with each browser prefix.  Yuck.  Another thing we...

  • By
    9 Mind-Blowing WebGL Demos

    As much as developers now loathe Flash, we're still playing a bit of catch up to natively duplicate the animation capabilities that Adobe's old technology provided us.  Of course we have canvas, an awesome technology, one which I highlighted 9 mind-blowing demos.  Another technology available...

Incredible Demos

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!