16

I want to replace my .png and .jpg files in android project with .webp to reduce the app size.

I am verifying these 3 cases for jpg to webp conversion(for both .png and .jpg) :

  1. Lossy with 80% quality
  2. Lossy with 100% quality
  3. Lossless

for Case 1, size was reduced by ~30% as expected

But for cases 1 and 2, size was increased significantly(170KB of .jpg to 470KB of .webp) instead of decreasing.

Command used :

cwebp -q 100 input.jpg -o output.webp

This is working fine with .png images for all three cases where sizes are reduced when converted to .webp format.

But the same is not working with the .jpg image ? Does size reduction depend on .jpg image ? Is size guaranteed to reduce when converted from .jpg/.png to .webp ? Why did the size increase ?

Version of libwebp : libwebp-0.4.3 OS - Windows 64-bit

userv
  • 2,527
  • 4
  • 27
  • 36
  • 1
    If you convert lossy to lossless, or lossy to lossy with higher quality than the input file, you'll gain no quality but the file size will always increase. – BladeCoder Jun 04 '15 at 10:20
  • 1
    Why the downvote ? Is it obvious for me to know that lossy to lossless will increase size ? Or how would i know JPG(input) quality is less than output quality (Case 2 above ) ? – userv Jun 04 '15 at 10:41
  • 4
    (Downvote is not cool, I agree) Lossy and lossless are 2 different things, it's like apples and oranges. lossless compression algorithms render the exact image so the ouput file is always bigger than lossy. The problem is, when you compress an image to Jpeg (lossy), it adds artifacts. So if you try to compress this jpeg image in Png (lossless), the lossless algorithm will encode each artifact to reproduce it pixel-perfectly. In the end this Png will be even bigger than if you encoded it straignt from source, because of the additional artifacts. – BladeCoder Jun 04 '15 at 11:54
  • 2
    Also you should understand that when you compress with lossy, you lose information from the image. After that, you have nothing to gain by applying a lossless compression: data is lost, it will not reappear. The only use case to recompress a lossy image is to compress it with an even lower lossy quality setting and lose more detail. – BladeCoder Jun 04 '15 at 12:11

2 Answers2

5

The problem you face is that with JPEG there is are large number of variables you can manipulate to get different compression. That is the benefit you get from lossy compression. Lossless compression tends to have few (if any options). In lossless compression, the tradeoff is time vs. compression. In lossy it is quality vs. compression.

You are running a lossy compressed image through a second lossy compression process and getting rather unpredictable results.

The real comparison would be to take your PNG images and compress them using webp and JPEG using various settings to see what quality you get compared to the compression.

user3344003
  • 20,574
  • 3
  • 26
  • 62
2

Including the reference to the Google documentation who came with the WebP format about the possibility of the file size getting increased when converted into the WebP format.

Yes, usually when converting from a lossy format to WebP lossless or vice versa. This is mainly due to the colorspace difference (YUV420 vs ARGB) and the conversion between these.

https://developers.google.com/speed/webp/faq#can_a_webp_image_grow_larger_than_its_source_image

Praveen Sripati
  • 32,799
  • 16
  • 80
  • 117