A photo of me wearing a blue blazer and pocket square while on a horse, looking quite dapper.

David Celis

A cowboy coder.

Follow me

i feel like i’m going fucking crazy. can someone please explain to me why Vips would be increasing the file size of a WebP when saving it with 90% quality???

> File.size(webp.path) / 1e6
=> 1.222172
> Vips::Image.new_from_file(webp.path).write_to_buffer(".webp", Q: 90).bytesize / 1e6
=> 1.763958
/ 🦣 / 🦋 Highland / Denver / CO 70°F and mostly clear  (AQI 20 )

Did you like this post, repost it, or respond to it? Let me know by sending a webmention!

🌐

💬 Replies (12)

FWIW this is also happening with my JPEGs. how do i vips 😭

```ruby

> File.size(jpeg.path) / 1e6
=> 2.521735
> Vips::Image.new_from_file(jpeg.path).write_to_buffer(".jpeg", Q: 90).bytesize / 1e6
=> 3.947971
```

@davidcelis I know nothing about VIPs but what are you trying to do?

@anderson_jon literally just trying to compress the photos i post to my site when cross-posting them to mastodon and bluesky. especially bluesky. because their file size limit is absurdly low at just under 1MB

@davidcelis my guess is that the original image was saved at a lower quality setting and that vips is starting over from the decompressed pixels when writing the new version at 90%. I think vips' webp default quality is 75?

IIRC, there's no real way to determine what quality level something was saved in. I remember that ImageMagick implemented some guesswork to try to figure it out.

@reid you can decompress the pixels??? i guess that would explain it, but i’m not explicitly doing any image compression when i upload to my site. i guess its possible that activestorage/image_processing has a default compression?

@davidcelis JPEG is already pretty compressed and lossy. Is VIPS compressing or just analyzing the photo? Can you use VIPS to resize it, which sounds more like what it is on my less than 3 minutes of reading, to an appropriate size and byte size? VIPS doesn’t *seem* like a compression algorithm or denser encoding method but more of a manipulation or analysis library.

Note again: 3 minutes of reading so. Hugest grain of salt.

@anderson_jon yeah, it's an image manipulation library, but the saver methods support compression. i’m just racking my brain as to why doing something like saving an image with what should be "80% quality" ends up producing a file with a bigger size

@davidcelis my best guess is it’s purely the image size. Some images are crazy big, like a foot by a foot, for no reason other than that’s what the megapixels kinda translate to. Can you shrink not by quality but by size? I wonder if shrinking to like 40% size on length and width would work better than quality.

@davidcelis tbh I think it’s better even if it sucks. You’re explicitly shrinking size then, not letting it algorithmicaly try and decide how “lossy” it can be.

@davidcelis maybe decompress isn't the right word? 90% isn't a relative compression value.

If I save a JPG from Photoshop at 10% and get a bunch of chunky artifacts all over it, then I open that 10% image and re-save it at 90%, the 90% one is like 4x bigger than the 10% one. All the artifacts are still there from the 10%, because that data was lost, but in the new 90% there's less re-compression.

@davidcelis I had a bunch of trouble getting consistent results with Vips and webp, they also don't handle animated webp well. I ended up using rust image/rust image webp. Alternatively shelling to imagemagik