{"id":667,"date":"2019-05-23T11:38:34","date_gmt":"2019-05-23T16:38:34","guid":{"rendered":"http:\/\/blog.mindworkshop.com\/?p=667"},"modified":"2023-07-17T20:37:17","modified_gmt":"2023-07-18T01:37:17","slug":"a-quick-introduction-to-webp-graphics-and-animations","status":"publish","type":"post","link":"https:\/\/blog.mindworkshop.com\/?p=667","title":{"rendered":"A Quick Introduction to WebP Graphics and Animations"},"content":{"rendered":"<p>The WebP format was developed by Google as a twenty-first century replacement for the aging hoard of mutant armadillos which has previously served the web as graphic standards. It can be used in place of still image formats, such as JPEG and PNG, and it really gets up and dances when it&#8217;s used to replace the medieval relic that is GIF to manage animations.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.mindworkshop.com\/image\/webp004.gif\" alt=\"picture\" align=\"right\" border=\"0\" \/><\/p>\n<p>WebP offers both lossless image compression like PNG and lossy image compression like JPEG. It uses vastly more effective image compression than existed when the foregoing formats were originally created back at the dawn of human civilization, resulting in both smaller animation files and better looking ones. It supports full alpha transparency.<\/p>\n<p>It also handles timing in milliseconds, rather than in the hundredths of a second that GIF uses.<\/p>\n<h6>A Digression On Compression<\/h6>\n<p>In case the whole lossless and lossy compression issue sounds a bit like two Martians discussing what to order for lunch, here\u2019s a brief digression on the matter.<\/p>\n<p>Graphic files are by their nature sort of huge, and huge files can be a bit of an issue if you have a finite amount of storage space, such as on the SD memory card of a digital camera, or a finite amount of bandwidth over which to transmit said files, such as the Internet if you didn\u2019t spring for a gigabit fiber connection.<\/p>\n<p><!--more--><\/p>\n<p>These inconsiderate aspects of the physical universe being pretty much insurmountable, graphics are typically stored with data compression to reduce the amount of space they occupy. In its simplest sense, data compression as it\u2019s applied to a picture would find areas of identically-colored pixels and replace them with a code that says, in effect \u201cthere used to be an area of identically-colored pixels here.\u201d When it comes time to unpack the graphic, the software that does so would interpret the codes for the areas of identically-colored pixels and correctly recreate the original picture.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.mindworkshop.com\/image\/webp001.webp\" alt=\"picture\" align=\"right\" border=\"0\" \/><\/p>\n<p>This is called \u201clossless\u201d compression. That which gets written to a lossless graphic document comes out of that document unchanged. Lossless compression is the basis of the PNG still image format used in web pages, among others.<\/p>\n<p>In dealing with photorealistic images \u2013 to wit, pictures from a digital camera \u2013 lossless compression usually finds itself in a bit of a box. Zoom in on a digital camera image and you\u2019ll probably find that most of the areas therein that look like they consist of identically-colored pixels actually don\u2019t. They\u2019ll exhibit minor variations in color due to shading and light effect. This would pretty much stop lossless compression in its tracks.<\/p>\n<p>&#8220;Lossy&#8221; compression cheats around this limitation, and it cheats quite effectively. In practice, there\u2019s more detail and color information in most digital images than our eyes actually require to perceive them as being photorealistic and reasonably attractive. This is even more the case when pictures appear at a web page, or in other on-line media, wherein we don\u2019t pay them much more than passing attention. It\u2019s possible to lose a bit of detail and color fidelity, making formerly almost identical pixels in fact identical, and in so doing allowing image compression to have something to work with.<\/p>\n<p>If the degree of color and detail degradation is chosen reasonably carefully, the result will be pictures that look like they haven\u2019t been meddled with, but which reside in way smaller files.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.mindworkshop.com\/image\/webp002.webp\" alt=\"picture\" align=\"right\" border=\"0\" \/><\/p>\n<p>The most commonly-encountered implementation of lossy compression is in what drives the JPEG still-image format. You can adjust the \u201cquality factor\u201d of whatever creates your JPEG graphics to store almost flawless reproductions of your pictures in somewhat huge files, horribly degraded versions of your graphics in very tiny files or \u2013 as is usually the case \u2013 a compromise between these two extremes, reasonably faithful pictures in files of a size you can get along with.<\/p>\n<p>The downsides to JPEG are:<\/p>\n<ul>\n<li>Its somewhat ancient and extremely complex data compression isn\u2019t all that effective, and also isn\u2019t entirely consistent among all the applications that read and write JPEG files<\/li>\n<li>Its primitive logic for simplifying your source graphics results in noticeable\u2026 and none too attractive\u2026 artifacts in stored images if you choose a quality factor that\u2019s a bit too aggressive.<\/li>\n<\/ul>\n<h6>Googling for WebP<\/h6>\n<p>The WebP graphic document format was designed from scratch for use on web pages and comparable media. It can store lossless still images, like PNG does, lossy still images like JPEG, and animations like GIF, but with way better color and more accurate timing.<\/p>\n<p>Because it uses more modern compression logic than its dusty ancestors, your graphics and animations will be smaller and yet more attractive if they\u2019re stored as WebP documents.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blog.mindworkshop.com\/image\/webp003.webp\" alt=\"picture\" align=\"right\" border=\"0\" \/><\/p>\n<p>You can use .webp files in a web page in precisely the same way as you would .jpg, .png or .gif files. Here\u2019s an example of the HTML coding for a .webp graphic or animation:<\/p>\n<p>&lt;img src=\u201dmygraphic.webp\u201d&gt;<\/p>\n<p>As of this writing, all the popular web browsers support WebP graphics and animations. If you\u2019re seeing four animations in this posting, yours is among them.<\/p>\n<p>The example animations in this posting illustrate some of the capabilities of .webp files. The first one is actually a GIF animation, resplendent in its patina of antiquity and its circa 1987 color space. GIF animations support a maximum of 256 unique colors, so some very crafty software has adjusted the colors in the first of these animations to get along with this limitation.<\/p>\n<p>If you look closely at the GIF animation, you\u2019ll notice that the shadow below the bear and behind the cube is a bit rough. The bear\u2019s nose has been rendered as a sequence of colored horizontal bands, rather than as a smooth color gradient.<\/p>\n<p>We hasten to add that this GIF animation was created using color remapping, rather than color dithering. Had the latter been used, the colored bands would have been less noticeable, but the whole animation would have been decidedly less sharp.<\/p>\n<p>The GIF animation occupies 208,493 bytes.<\/p>\n<p>The second animation is a lossless WebP document. If you plant your face directly in front of your monitor, you\u2019ll notice that the shadow detail is much more distinct and lifelike, and the bear\u2019s nose suffers from no banding or compression artifacts.<\/p>\n<p>The lossless WebP animation occupies 388,972 bytes \u2013 it\u2019s larger than the GIF animation, but arguably worth the hit.<\/p>\n<p>The third animation is a lossy WebP document in which the quality factor has been set to 75, this being the usual default for lossy compression. It will require a keen eye and a modest degree of imagination to distinguish it from the lossless animation.<\/p>\n<p>The lossy WebP animation of reasonable quality occupies a mere 110,788 bytes, just over half of what the GIF file needed, and it looks substantially better.<\/p>\n<p>The final animation is a lossy WebP document with a quality factor of 10\u2026 which is somewhere you probably never want to go. It exhibits lots of color and detail loss, and noticeable compression artefacts in the moving cube and the shadow thereof, which periodically deteriorate into solid rectangles.<\/p>\n<p>The extremely lossy WebP animation occupies 51,934 bytes.<\/p>\n<p>In practice \u2013 should you find your web pages choked for storage space or bandwidth \u2013 most animations can be squeezed into lossy WebP documents with quality factors slightly lower than 75 with no obvious loss of quality. Some experimentation may be called for.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The WebP format was developed by Google as a twenty-first century replacement for the aging hoard of mutant armadillos which has previously served the web as graphic standards. It can be used in place of still image formats, such as JPEG and PNG, and it really gets up and dances when it&#8217;s used to replace [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-667","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/blog.mindworkshop.com\/index.php?rest_route=\/wp\/v2\/posts\/667","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.mindworkshop.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.mindworkshop.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.mindworkshop.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.mindworkshop.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=667"}],"version-history":[{"count":0,"href":"https:\/\/blog.mindworkshop.com\/index.php?rest_route=\/wp\/v2\/posts\/667\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.mindworkshop.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=667"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.mindworkshop.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=667"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.mindworkshop.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=667"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}