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
    39 Shirts – Leaving Mozilla

    In 2001 I had just graduated from a small town high school and headed off to a small town college. I found myself in the quaint computer lab where the substandard computers featured two browsers: Internet Explorer and Mozilla. It was this lab where I fell...

  • By
    CSS Filters

    CSS filter support recently landed within WebKit nightlies. CSS filters provide a method for modifying the rendering of a basic DOM element, image, or video. CSS filters allow for blurring, warping, and modifying the color intensity of elements. Let's have...

Incredible Demos

  • By
    Element Position Swapping Using MooTools 1.2

    We all know that MooTools 1.2 can do some pretty awesome animations. What if we want to quickly make two element swap positions without a lot of fuss? Now you can by implementing a MooTools swap() method. MooTools 1.2 Implementation MooTools 1.2 Usage To call the swap...

  • By
    CSS Animations Between Media Queries

    CSS animations are right up there with sliced bread. CSS animations are efficient because they can be hardware accelerated, they require no JavaScript overhead, and they are composed of very little CSS code. Quite often we add CSS transforms to elements via CSS during...

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!