Open borisblizzard opened 3 years ago
That is really cool. Is this as good as running optipng? I usually do run this command prior to uploading my asset and I so save usually 25% without affecting quality.
Btw, I've tried your change and I could not see any difference in terms of file size...
Though after running optipng on my build/images folder I got from 704K to 332K (or a 53% reduction)
That is really cool. Is this as good as running optipng? I usually do run this command prior to uploading my asset and I so save usually 25% without affecting quality.
Btw, I've tried your change and I could not see any difference in terms of file size...
Though after running optipng on my build/images folder I got from 704K to 332K (or a 53% reduction)
Yup, this is like using optipng afterwards. The compression level is defined by the zlib standard and PNG uses zlib compression. All optipng really does is decompress the PNG and compress it again at level 9.
Since some blockchains charge more for minting larger images (larger as in more bytes, not larger dimensions), I suggest that PNG ZLIB compression level is set to the maximum value of 9 by default. This produces smaller PNG files, but the compression is still lossless and won't affect the image quality in any way.
This can be achieved by changing this line in main.js (line 111 at the time of writing):
fs.writeFileSync( `${buildDir}/images/${_editionCount}.png`, canvas.toBuffer("image/png") );
To this:
fs.writeFileSync( `${buildDir}/images/${_editionCount}.png`, canvas.toBuffer("image/png", {compressionLevel: 9}) );