tayloraswift / swift-png

decode, inspect, edit, and encode png images in pure swift

Home Page:https://swiftinit.org/docs/swift-png

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Compressed image is bigger than the original

ospfranco opened this issue · comments

Once again, thanks for the library! This issue is related to my previous one. I'm basically trying to compress/optimize for file size as much as I can, yet the image I get from the .compress (with level 13) call is bigger than the original one by a huge margin, I imagine because extra bits are being used/padded per pixel.

Any recommendation to aggressively reduce file size?

Screenshot 000807

hi, can you share the smaller image?

Thanks for replying, I gave up on this idea. The image was just a screenshot I took from my desktop using cmd + shift + 4 nothing special about it. Feel free to close the ticket, otherwise just leave it open as future reference for people trying to reduce file size.

okay, i'm still very interested in how the first image is half the size, so if you have time to attach a copy of it, that would be greatly appreciated :)

Sorry, I already deleted the file I was using for testing.

I can give you this image:

Screenshot 000814_1659371004 521134_optimized

I ran it through pngquant which was the library I was looking to replace with swift-png. The image size is as small as it gets (tinyPNG produces an even smaller file, but they are closed source). I would have liked for swift-png to have produced such a small file size, or at least close to it, even if it required tweaking.

This is the original screenshot taken with cleanShotX

Screenshot 000814

ah, that explains it! pngquant is a lossy image compressor, swift-png is a lossless image codec. lossy algorithms will of course produce smaller output files, but at the expense of information loss and ability to re-encode.

Makes sense 👍 thanks!