Is webp format more efficient than JPEG?
Asked Answered
D

4

7

I am trying to compress and resize DSLR camera photos. But my observation so far is that webp has noticeable degraded quality when webp file size is about 30% smaller than JPEG.

Command used to generate webp using imagemagick:

convert 1.JPG -strip -quality 80 -resize 800 -define webp:method=6 1.webp

My goal is to get webp format that is at least 20% samller file size than JPEG while having virtually no difference in quality between JPEG and webp. Is this achievable or again there is no such thing as free lunch?

Debase answered 12/4, 2019 at 16:36 Comment(0)
L
8

Update Since the time of the original posting, I've discovered that using Google's cwebp compressor shows dramatically improved compression over ImageMagik 6.7.8, which is what powered my initial tests. This is especially true for images with transparency when compared to PNGs. Files using the mac version of the webp command (which uses cwebp under the hood) are about 1/4 of the size of the same file compressed with ImageMagik, and do provide a significant performance boost.


According to Google, "WebP typically acheives an average of 30% more compression than JPG" (source) with similar visual quality to a JPG. However, as you suggest, there in never such a thing as a free lunch.

Quality Quality is largely a subjective measure, but keep in mind that you're comparing a file compressed at quality 80 with a file that doesn't have that level of compression (at least, this is what I understand from your question). Just running the default conversion without specifying a lower quality may give you slightly smaller files without loss of visible quality. 20% smaller might be a bit much of an ask, though, but it may be achievable for certain images.

convert 1.JPG 1.webp # do not specify quality

Size In practice, it depends a lot on your settings and your source images. For example, I recently ran this command on all jpg images in a folder on a website "in the wild":

convert filename.jpg -quality 80 -strip -define webp:lossless=false -define webp:method=6 filename.webp

The convert command on this particular server is powered by ImageMagick 6.7.8. Some files were dramatically smaller compared to the original JPGs, while others were actually larger. Overall, after running that command, the total file sizes of all JPG images was 49MB, while the total file size of all WebP images was 29MB. That's a pretty good savings, however, when I ran ImageMagick's JPG compression, it was even better:

convert filename.jpg -sampling-factor 4:2:0 -strip -quality 80 -interlace JPEG filename-new.jpg;

The size of all new jpgs in the directory was 21MB. Both are set to compress at quality 80, but the jpg compression appears to be better. This may have to do with some compression already on my set of test images and how that interacts with the WebP conversion process.

As I found, file sizes can even grow, usually if you are converting between lossy and lossless images. On the FAQ page linked above, Google claims: "this is mainly due to the colorspace difference (YUV420 vs ARGB) and the conversion between these."

tl;dr: In the wild, it may or may not improve file size depending on the type of images, if/how the source file was compressed, and what quality you set for the WebP. Visible degradation is harder thing to measure, but try setting a higher quality, or without specifying a quality at all.

Literally answered 15/5, 2019 at 20:58 Comment(1)
At least ImageMagick 7.0.10 results in exactly the same files as cwebp, when executed with the same options. This shouldn't be any surprise, as both are using libwebp. If anyone has some big differences between imagemagick and cwebp, I'd double check settings. I suspect webp on your mac have some defaults changed.Sherr
P
6

Just to add a side-comment to @Pwpwpw's excellent answer, webp is a good PNG replacement, but not great as a JPG replacement.

It beats PNG because it has better lossless compression algorithm than libpng, and it has the great feature of allowing different compression settings for different channels. You can do lossless on the alpha but lossy on the RGB, for example, which is fantastic for overlays.

Against JPG it does less well. It uses the VP8 codec for lossy, which is only somewhat better than JPG.

I would take a look at HEIC. It uses the much more modern h.265 for lossy compression and typically beats JPG by a factor of two at the same quality. It's the format Apple are using by default on iOS now.

libheif have a nice demo here:

https://strukturag.github.io/libheif/

That's libheif, compiled to javascript and running in your browser. You can upload .heic to it and download as jpg. libheif have some basic command-line tools to encode and decode images.

It does sadly have some patent issues, you might need to be a little cautious.

update Looking further out, the current hope is AVIF: it's the same container format as HEIC (called HEIF, confusingly), but swaps the problematic h.265 compressor for AV1. AV1 is roughly equivalent to h.265, but is patent-free.

update for 2022 AVIF seems to be too slow to be practical, so now hope rests on JXL. It's fast, patent free, supports HDR, transparency, etc., and compression is as good as HEIC. Chrome has support, though it's behind a flag for now.

Papke answered 16/5, 2019 at 10:15 Comment(4)
how does HEIF compared to WEBP ?Enchantment
WEBP and JPEG are broadly similar for lossy images. HEIC images are about half the size. AVIF is the up and coming patent-free competitor to HEIC.Papke
In my current tests, trying to switch from .jpg to .avif, the results were quite disappointing or minimal. I had wished for something more drastic like .tar.gz to .tar.xz (I know, can not be compared 1:1 but you understand the point of view coming from minimizing storage requirements here).Hexastyle
Try: $ vips copy k2.jpg x.avif[Q=30,compression=av1]; ls -l k2.jpg x.avif with a photo. I see eg. 270k for the jpg and 120k for the avif, and they are visually very close.Papke
R
6

You are re-encoding lossy compressed jpeg; if you have access to the original raw files you should use them as master. Currently you are compressing noise (and other artefacts) introduced by the jpeg encoder so the WebP codec does not have access to the same information that was already lost at the jpeg encoding. Of course it will look worse.

In other words; you should encode the original image data, if possible. I'm aware that some cameras and equipment only outputs HEIC / JPEG and not RAW so you might be out of options - the best thing to do is to keep the JPEGs as JPEGs.

Rihana answered 28/8, 2019 at 7:55 Comment(1)
I guess this is a good answer, so for original raw images, converting to .avif or webp-based formats is better than the old .jpg. I thought that even converting .jpg that were already compressed, into .avif, would have useful results, but I even have images that are bigger in .avif, so that was hugely disappointing. :( Guess this shows that the most important step is the one where you decide how to save file space, while still having the original large(r) image.Hexastyle
R
2

Just did a quick test with a high-res JPG from my DSLR camera converting to a 410x800 background picture for mobile using Photoshop CC 2020 (and the WebPShop plugin).

Lossless:

  • PNG 100%: 680 KB
  • JPG 12 (max): 428 KB
  • WEBP 100%: 537 KB

50% quality:

  • JPG 6 (50%): 119KB
  • WEBP 50%: 45KB

At 50% JPG has more detail, but quite comparable quality.

0 quality:

  • JPG 0 (min): 51KB
  • WEBP 0%: 6KB

At 0% WEBP is horrible. But imagine the lowest quality JPG, and that's bad image quality and WEBP definitely beats it at 50%, while still being smaller in file size. So for me.. that's free lunch.

Richey answered 24/3, 2020 at 9:14 Comment(3)
It's still quite disappointing to me; I have many smaller .jpg files too, so putting them into .avif isn't quite worth it. Perhaps for larger images that may be useful but currently I am quite disappointed considering how much .avif is promoted on the www, yet the results aren't that awesome really ... yes, better than jpg but it's nowhere near as much as, say, you had gained in the video-segment from the year 1995 to 2020, just as a comparison.Hexastyle
don't compare the same% quality, since different formats use different quality scales... compare the same size. "at 0% webp is horrible" yes but it's 10x smaller. notice that 50% quality webp is smaller than 0% quality jpeg...Thiamine
Downvoted because somebody is right. t0rakka too.Ency

© 2022 - 2024 — McMap. All rights reserved.