Image format size pickle

General discussion about LÖVE, Lua, game development, puns, and unicorns.
RNavega
Party member
Posts: 385
Joined: Sun Aug 16, 2020 1:28 pm

Re: Image format size pickle

Post by RNavega »

BrotSagtMist wrote: Wed May 01, 2024 12:18 am And if we imagine a whole class result of paintings, thats 30 students, and we try to flip "rooms" it has to reload 300mb from the sd card everytime as opposed to 30. Thats not a lot by modern standarts but still a loading time.
It's probably out of scope, but taking e-commerce as a reference, they use a lot of thumbnails for products. Then only when the visitor hovers the mouse over the thumbnail, or clicks to visit the page etc. is when they load the high-res picture. The high-res asset is loaded on demand.
So the photos for this gallery project could be arranged in two folders, thumbnails vs originals.
Then upon the user approaching / zooming in past some point, the high-res version for a picture on screen is loaded and used instead of its thumbnail.
User avatar
knorke
Party member
Posts: 274
Joined: Wed Jul 14, 2010 7:06 pm
Contact:

Re: Image format size pickle

Post by knorke »

Disclaimer: I am not sure if I have 100% understood what you are trying to do.
BrotSagtMist wrote: Tue Apr 30, 2024 4:11 pmOkey number wise i just realized the problem is bigger than a thought.
The same file that as a jpg only takes 620kb is 10.8mb as a png.
Even when removing colours to a hefty quality drop png still stays in the several mb range.
I tried some of the compressed file formats and they dont do much either, dxt5 results in 8.3mb.
That is why I meant to use jpg for photo but png for the transparency.

png compresses very well if there are few colors. The picture quality stays the same, no blurring. With many colors used the file size is larger than jpg.
jpg compresses well with many colors but the pictures becomes "blurred."

example: jpg as taken by smartphone camera: 2,5 MB
With 60% compression jpg: 800 KB
black/white "mask" as png: 7 KB
The mask I just made in 10 seconds with Inkscape polygon tool so it is quite rough.

The "mask" could likely be in lower resolution than the photo. For example photos in 2560x2560 pixels and mask in 640x640 pixels.
But the png is already only 7 KB so it does not save that much.
Attachments
imageTrans.love
flashing colors, beware
(803.45 KiB) Downloaded 111 times
lokpng.png
lokpng.png (6.85 KiB) Viewed 2424 times
lokjpg60.jpg
lokjpg60.jpg (799.84 KiB) Viewed 2424 times
User avatar
pgimeno
Party member
Posts: 3672
Joined: Sun Oct 18, 2015 2:58 pm

Re: Image format size pickle

Post by pgimeno »

Also, have you tried PNG optimizers?

apt-cache search png optimize
User avatar
dusoft
Party member
Posts: 654
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Image format size pickle

Post by dusoft »

User avatar
BrotSagtMist
Party member
Posts: 659
Joined: Fri Aug 06, 2021 10:30 pm

Re: Image format size pickle

Post by BrotSagtMist »

Yes knorke i know how masks work and they are in consideration, i just dont like using them for this tasks.

I just tried optipng, that sounded promising, i was looking for exatly that, BUT it only reduced the 10.8mb file to a lousy 10.4mb which is even worse than having gimp do it. :crazy:
obey
User avatar
pgimeno
Party member
Posts: 3672
Joined: Sun Oct 18, 2015 2:58 pm

Re: Image format size pickle

Post by pgimeno »

BrotSagtMist wrote: Wed May 01, 2024 2:09 pm Yes knorke i know how masks work and they are in consideration, i just dont like using them for this tasks.

I just tried optipng, that sounded promising, i was looking for exatly that, BUT it only reduced the 10.8mb file to a lousy 10.4mb which is even worse than having gimp do it. :crazy:
Here's what `apt-cache search png optimize` shows for me (in bold the relevant ones):

apngopt - optimize APNG animated images
imgp - Superfast batch image resizer and rotator
optipng - advanced PNG (Portable Network Graphics) optimizer
pngcrush - optimizes PNG (Portable Network Graphics) files
pngnq - tool for optimizing PNG (Portable Network Graphics) images
pngquant - PNG (Portable Network Graphics) image optimising utility
ruby-chunky-png - pure ruby library for read/write, chunk-level access to PNG files
trimage - GUI and command-line interface to optimize image files
w3-recs - Recommendations of the World Wide Web Consortium (W3C)

With default options, optipng and pngcrush did next to nothing to a 18 MB PNG image (converted from a 5 MB JPG), while pngquant reduced it to 6.0 MB file and pngnq to a 6.3 MB file. Personally I liked the pngquant result better, because it used Floyd-Steinberg; probably pngnq has some option to activate that but I haven't looked.
User avatar
BrotSagtMist
Party member
Posts: 659
Joined: Fri Aug 06, 2021 10:30 pm

Re: Image format size pickle

Post by BrotSagtMist »

Oh wow thanks for finding these, so i tried them on the 10mb file and it gave a 40% reduction to 6mb.
But THEN i tried them on a file where i already added an alpha layer and did the cutout and the reduction was over 60%.
I can live with that.

I also found another stupid method: just save the file as jpg and use its quality slider, a 90% quality jpg has practically no visible quality drop, then convert the file back to png and voila, its half its size.
Must be the whole "made for photos" thing when working with photos.
Of course this is cumbersome if we try to work with transparency because it needs like a dozen steps to get that back into the file.
obey
User avatar
pgimeno
Party member
Posts: 3672
Joined: Sun Oct 18, 2015 2:58 pm

Re: Image format size pickle

Post by pgimeno »

Most of these, if not all, are scriptable though. ImageMagick's `convert` can reduce the quality of a JPG and convert it to PNG.
User avatar
BrotSagtMist
Party member
Posts: 659
Joined: Fri Aug 06, 2021 10:30 pm

Re: Image format size pickle

Post by BrotSagtMist »

Yea but i need to infuse the transparency between that.
I have not tried yet but i will probably generate it in Löve itself so i end up with a badly compressed png here.
obey
User avatar
darkfrei
Party member
Posts: 1204
Joined: Sat Feb 08, 2020 11:09 pm

Re: Image format size pickle

Post by darkfrei »

You can use this PNG optimization script: https://forums.factorio.com/viewtopic.p ... 71#p250171
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests