Page 2 of 2

Re: Image format size pickle

Posted: Wed May 01, 2024 12:41 am
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.

Re: Image format size pickle

Posted: Wed May 01, 2024 7:16 am
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.

Re: Image format size pickle

Posted: Wed May 01, 2024 7:48 am
by pgimeno
Also, have you tried PNG optimizers?

apt-cache search png optimize

Re: Image format size pickle

Posted: Wed May 01, 2024 9:51 am
by dusoft

Re: Image format size pickle

Posted: Wed May 01, 2024 2:09 pm
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:

Re: Image format size pickle

Posted: Wed May 01, 2024 2:41 pm
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.

Re: Image format size pickle

Posted: Wed May 01, 2024 3:06 pm
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.

Re: Image format size pickle

Posted: Wed May 01, 2024 4:08 pm
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.

Re: Image format size pickle

Posted: Wed May 01, 2024 4:17 pm
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.

Re: Image format size pickle

Posted: Wed May 01, 2024 7:05 pm
by darkfrei
You can use this PNG optimization script: https://forums.factorio.com/viewtopic.p ... 71#p250171