I took all the images (All PNG files) in my current platformer project and ran them all (Game assets, UI assets and everything) through the program and took a folder that was 1.7MB down to 118KB.
Now the question is why, how, and is this a bad thing? According to the documentation it's compressing the data stream in the file. Now when I think images and compression I think JPEG. But I don't want to think it's actually losing any image quality. I open the different versions in Preview or PhotoShop and they all look the same. No differences. Pixels all match. So why is PhotoShop creating such a bloated image? (One image is 29,111 bytes vs a crushed 986 bytes)
Then you have Löve which can also create PNG files from imagedata. I'm currently fiddling around creating an image editor for my game. (Partly out of boredom. Partly out of the dream to be able to create as many assets for the game from within the game itself.) So I save a file and it gets a different size as well. The same image as above comes out to 2,355 bytes instead. Nowhere near as big as the PhotoShop version, but not as small as a crushed one. Basically the code for saving a canvas to an image is as follows:
Code: Select all
local w, h = canvas:getWidth(), canvas:getHeight()
imageData = love.image.newImageData(w, h)
imageData:paste(canvas:getImageData(), 0, 0, 0, 0, w, h)
imageData:encode(filename)
Now if I run the Löve version through PNGCrush, I get yet another file size. 479 bytes. Which is smaller than the crushed PhotoShop version. Then if I crush it once more, it goes down to 472 bytes.
How is this possible without losing visual data? And how small can it go? And is it even worth doing? And if it's not really a big deal, is it a bad thing for Löve? Or does Löve not really care? And if a PNG can be made smaller, why doesn't Löve's ImageData:encode() function use a better compression algorithm?