Scanlators! Optimize your PNG's to losslessly decrease file size before uploading!

Member
Joined
Aug 21, 2019
Messages
30
I have been downloading and archiving from this site for a while now and I have noticed that so many of the PNG files could be optimized, some times it might only save about 1% but a lot of the time it's between 10% to 50% of space saved!

For example I just optimized 322 pages of some recent chapters and the total size for those files went from 244 mb to 207 mb. This could save on a lot of data use and storage for both users, the website and yourself.
Here is another more specific example : https://mangadex.org/chapter/876174/1 the first page in this chapter is 2.19 MB and after optimizing it's only 1.21 MB, the rest of the chapter is about the same.

I use the command line program OptiPNG to do this: http://optipng.sourceforge.net/ , I use a very basic script i found online that optimizes and overwrites all the PNG png files located in the folders and sub folders of the script and here it is: https://pastebin.com/Kx3iEBT7 To use this, save this as a .bat file, place it in a folder where the PNGs are and download optipng and put optipng.exe in the user folder. Again, if you run this bat file it will optimize and replace all the PNG files of where it's placed so be careful if something goes wrong.

EDIT: Use Pingo this instead, better and waaay faster:
Code:
[USER=6036]@ECHO[/USER] OFF
SETLOCAL
SET "sourcedir=%~dp0"
FOR /r "%sourcedir%" %%a IN (*.png) DO (
 pingo.exe -s9 "%%a"
)
pause
GOTO :EOF
EDIT: Changed it to higher compression with
Code:
-s9
instead of
Code:
-s1
, it doesn't slow it that much but saves the website a lot.

1. Copy the script above into notepad and save it as something memorable like
Code:
optimizePNGsinfolder.bat
2. Download pingo: https://css-ig.net/bin/pingo-win64.zip
3. Extract
Code:
pingo.exe
to your user folder.
4. Make a new dedicated folder for optimizing PNGs and put the script in it with some copies of the PNGs (always keep backups)
5. Double click the script

EDIT2: This is way faster than the script i used above.. https://css-ig.net/articles/pingo-examples or just use the gui tool: https://css-ig.net/pingo
I can't get it to do a specific folder+subfolder and only PNGs using the commandline too though...

EDIT3: This script is still maybe the easiest way to lazily optimize all the png files in a folder including subfolders, the pinga gui tool is faster but it also slows down your PC and it doesn't seem to remember your settings always. The script is consistent and not super slow.

I bet there are better guides,scripts and/or software to do this exact thing so if you know any link em here. I'm not a scanlator or know much of the scene so I apologize for anything I might have missed.

TLDR:
Scanlators, consider optimizing the PNG files before you upload them to save this site some money.
Any users who has manga saved could also run this script and save some space. (still the script is pretty slow)
 
Group Leader
Joined
May 2, 2018
Messages
120
You don't need any external software. Just use the "Save for web" --> "PNG-8" option on Photoshop. This is the result for the first image of the chapter you used as an example: https://i.imgur.com/kzzBe1a.png
As you can see, it's only 1.24 MiB, which is very close to what you got using OptiPNG.
I used similar software for compressing PNGs in the past (for example, PNG Gauntlet), but it's just not worth it. Usually, the difference is just 1% or even less, for 1600 px height grayscale images.
 
Group Leader
Joined
Jul 15, 2019
Messages
7,239
am i too stupid or what ?? how does all of it work ? does all the picture saves in one file or sometin ?
 
Joined
Aug 7, 2018
Messages
17
For Windows/Linux, pingo/pinga (the successor to ScriptPNG) set to
Code:
Lossless(Web) Extreme
is what I'd recommend if looking for a modern multi-threaded option. It losslessly optimizes colorspace (RGB to Grayscale if no color, remove Alpha if empty, strips metadata if desired) and offers compression comparable to bruteforce options using zopfli but is extremely fast. For the example in the first post, it produces a 1.18MB image in about a second.
 
Member
Joined
Aug 21, 2019
Messages
30
If this pingo program could run a script like the one in the first post but way faster you could just create the PNG's the using the exact same method you used before and not lose any meaningful time in the end. If it's just one extra click while all the images occupy the same folder then then it sounds very much worth it even if it's 2% space saved, at least if you consider all the bandwidth this site uses.

If anyone could throw together an equivalent script that lets you optimize images in a folder but faster then please share it here. I might try to figure it out otherwise but I'm no cmd expert..
got it
 
Contributor
Joined
Jan 21, 2018
Messages
1,083
I use pnggauntlet, it works good enough.

But before that, better set the pages to grayscale and throw all the colors away for the non-colored pages.
 
Member
Joined
Aug 21, 2019
Messages
30
@Cyberbeing Wow, pingo was waaay better! I modified the script and it chewed through that chapter in the first post in like 8 seconds on my 4690K and it was even smaller!
Here is the updated script:

Code:
[USER=6036]@ECHO[/USER] OFF
SETLOCAL
SET "sourcedir=%~dp0"
FOR /r "%sourcedir%" %%a IN (*.png) DO (
 pingo.exe -s9 "%%a"
)
pause
GOTO :EOF
EDIT: Changed it to higher compression with
Code:
-s9
instead of
Code:
-s1
, it doesn't slow it that much but saves the website a lot.

[ol]1. Copy the script above into notepad and save it as something memorable like
Code:
optimizePNGsinfolder.bat
.
2. Download pingo: https://css-ig.net/bin/pingo-win64.zip
3. Extract pingo.exe in your user folder.
4. Make a new dedicated folder for optimizing PNGs and put the script in it with some copies of the PNGs (always keep backups)
5. Double click the script[/ol]

Now you can use whatever workflow you already use to create PNGs and just run this script when you're done.
 
Contributor
Joined
Jan 18, 2018
Messages
203
Something else you forgot to mention is this helps with user load times. The sites just generally going to load pages faster if they're smaller. This definitely benefits the reader as well as the site.
 
Member
Joined
Aug 21, 2019
Messages
30
Mangadex is gonna do this serverside now to save 1.5 TB, this is great! https://mangadex.org/thread/250545/1/#post_2131669 I wonder if someone saw my thread, they probably had been thinking about this for a while also though.

I've been considering to convert all my archived manga to webp recently...
 
Group Leader
Joined
Jan 27, 2019
Messages
875
8rCQOsk.jpg
I uh, am very not computer literate. I'm barely even Japanese literate and I use paint.net lol. I have no idea what any of this means but is there a setting in good ole paint that'll help? Or should I ask my editor with photoshop to try and take care of this lol
 
Member
Joined
Aug 21, 2019
Messages
30
@gomichandesu I checked went to your profile and downloaded a couple of pages and it seems you're doing ok so far! 😉

This is fairly low compared to other less stuff i see which is maybe 5% to 50% saved
Code:
pingo - (1.36s):
  -----------------------------------------------------------------
  1 file => 8.93 KB - (1.28%) saved
  -----------------------------------------------------------------

 pingo - (1.44s):
  -----------------------------------------------------------------
  1 file => 8.59 KB - (1.23%) saved
  -----------------------------------------------------------------

  pingo - (1.37s):
  -----------------------------------------------------------------
  1 file => 3.80 KB - (0.46%) saved
  -----------------------------------------------------------------
So maybe it's not a huge priority in your case but it still can't hurt to save those kilobytes because they add up for the site.

It might be a bit confusing to set this script up but when that's done all you do is you put all the png files in a folder, click the script in the folder and it starts shrinking all the files until it's done. That means it's only one extra click and maybe 1.5s wait per file.

Here is the extra simple/detailed instructions if you wanna give it a try: (this had way more steps than imagined at first...)

[ol]1. Click this link: https://pastebin.com/EdT2ZqhQ
2. Click the download button just above the text to the right
3. Save the file it gives you, it should be named
Code:
pingo-png-optimize-this-folder.bat.txt
4. Rename the file so it's just named
Code:
pingo-png-optimize-this-folder.bat
, just remove the
Code:
.txt
part
5. If you can't see the
Code:
.txt
part, follow this guide on how to change file extensions: https://www.wikihow.com/Change-a-File-Extension
6. Create a new folder for optimizing png, name it something useful like
Code:
Optimize PNGs
7. Move the file
Code:
pingo-png-optimize-this-folder.bat
to your newly created folder.
8. Click this link and download the file: https://css-ig.net/bin/pingo-win64.zip
9. Find your user folder, that's the folder that has the same name as your username on windows. You can usually find it in the
Code:
C:\Users
folder. You can also get to it quickly by hitting Win+R on your keyboard then pasting in
Code:
%userprofile%
and then press OK.
10. Open the pingo-win64.zip file you downloaded earlier and unzip the pingo.exe file in that folder. Guide for unzipping if needed: https://www.wikihow.com/Unzip-a-File
11. Make sure that the exe file is now inside the user folder, and not inside some other folder.
12. Now that exe is in the folder and that's it, you just leave it there. You don't click the exe file ever. Close that folder.[/ol]
Now all the setup is done! You only do this once.

This is how you use the script
[ol]1. Copy some PNG files to
Code:
Optimize PNGs
It's important copy so you have a backup if the program eats your images or something else bad happens.
2. Now you have one or more png files in a folder together with the
Code:
pingo-png-optimize-this-folder.bat
file right?
3. Double click the
Code:
pingo-png-optimize-this-folder.bat
file, this opens a black console window that shows the progress for every file.
4. Wait a bit until it stops and it says Press any key to continue . . .[/ol]
Now all the PNG's are optimized! Compare the sizes and open them to check if they look any different. Now next time you can just save all the completed images to this folder, run the script and then you're done.
 
Joined
Nov 25, 2018
Messages
3
You can also tell Pingo to do a specific folder by using this command:

pingo options folder location

for example:

pingo -s1 c:\myfolder\mysubfolder1

if it is a mounted network harddisk

pingo -s1 \\192.168.1.2\myfolder\*.png

you can use this command in erati's script by changing these line:
FOR /r "%sourcedir%" %%a IN (*.png) DO (
pingo.exe -s9 "%%a"
)

to:
pingo -s1 c:\myfolder\mysubfolder1 <-- folder location can be copied from file explorer address bar

this will make it so that you can place the script and folder anywhere you want, the pingo.exe files need to be in the same folder as erati's script

these command are from https://css-ig.net/articles/pingo-examples
 
Dex-chan lover
Joined
Mar 24, 2018
Messages
623
@erati
Let do some fun stuff.
change: pingo.exe -s9 "%%a"
to: c:\pinga\pingo.exe -pngpalette=100 -notrans -s9 "%%a"

What you get for it. Don't have to use pingo.exe in the source directory. Explicit access to the executable. Pingo location doesn't change it always install there.
-notrans get rid of transparencies. Never did like that part of PNG's.
-pngpalette=100 limit the BPP to 8. 256 color pallette. On large 24 BPP pngs the reduction was dramatic. 50%-70%. Color in PNG didn't notice a difference.

Now I just have to get recursive directory tree's to work. ie: "\dir\subdir\subdir\file.png" Yea I got those that kind of dir's.

Changing to 256 color palette is good. For grey scaled PNG the eye won't see it. Color would be very hard to detect.
 
Member
Joined
Aug 21, 2019
Messages
30
@molen I could never get pingo to use one folder at a time while also only doing png's AND all subfolders but i tried that command now and it seems to work, maybe I did it wrong. Your edit should work just fine but it would make it more specialized for one directory, users who want to try it would need to edit the script based on where their files are and stuff.

Also the main feature of the script I posted (which is totally not mine BTW, i edited some script made for optipng that i found while googling...)
...Anyway, the main feature of that script for me is that you can copy it and put it in any directory where PNG's might show up and just double click it and just leave it to work. No need to edit scripts, type filepaths or open cmd. Just the easy method of copying the script to another directory and double clicking it.

That said, maybe I could use the switches of pingo more and get it do the current folder of the script and any subfolders individually instead of each file one by one.. I don't have the scripting skills to fix that currently but with some googling I might.. Still if I don't it might be fine anyway, the current method is a bit verbose and maybe a tad slower but that's about it. If anyone reading this could make this work then share your work here!

@doppler Those switches look interesting, I will need to try those.

Changing the source of the might make the setup a bit easier but I would probably change it to
Code:
C:\Program Files\pinga\pingo.exe
since that's the default install location, still this would make the setup a bit easier for people who don't know what a userfolder is. They could just run the installer and be done with that part.

Hey speaking of userfolders @molen and @doppler: You both seem to have missed step 3 in my setup instructions in the last post or something, you don't need to have pinga.exe in the same directory as the script. Or at least you shouldn't need to If you put a file in the userdirectory in windows it should be executable using the command line no matter what directory you're running it from or where the script is located. All the script needs is the name of a file in the userdirectory or the current directory. That's why you unzip the pinga.exe file to your userdirectory, so you can move the script (and only the script) to any folder and optimize png's anywhere on your computer. More info: https://en.wikipedia.org/wiki/PATH_%28variable%29
Just wanted to clear that up, thanks for your suggestions but I will leave the script in the original post for now. You should both post any improvement you make and just post the entire edited script, makes it easier to copy and paste for everyone. People can just copy whatever seems better to them 😊
 
Dex-chan lover
Joined
Mar 24, 2018
Messages
623
Using path for everything is not a good idea. The environment labels tho expanded for NTFS type O/S's do have a limit. When you reach that limit the system can do unpredictable things. Getting totally borked is one of them. This is a work around from the old days when the limit was 256 bytes. Even the GDI heap had limits then too, so too much graphic windows can bork today as well. Besides I don't want certain programs to just start out of nowhere because I got sloppy in a BAT Script. Absolute paths are a benefit.

Using pingo GUI install program is not fun. Because every time you use it. It will overwrite the INI file. You lose all set variables within the program. Using program files and program files (x86) directories is not easy when changes like resetting the INI file needs to be done. UAC and admin rights are need to change anything in those folders and sub folders. A real pain. Anything off C: root is changeable without UAC interruption. So I leave it in c:\pinga.
 
Member
Joined
Aug 21, 2019
Messages
30
Ah, I see. that seems to makes sense, thanks for clarifying.

I still haven't tried the other stuff you added, all that color stuff seems scary for non-grayscale images but I will try it later when I have the chance.
 
Dex-chan lover
Joined
Mar 24, 2018
Messages
623
@erati
Let do some EVEN MORE fun stuff.
change: c:\pinga\pingo.exe -pngpalette=100 -notrans -s9 "%%a"
to: c:\pinga\pingo.exe -q -nodate -pngpalette=40 -notrans -s9 "%%a"

I dug into the process of pinga gui. I was able to glean out the command line used by it. I Used system internals ProcessExplorer. Won't bother going over the old stuff.
Two new and two changes.
Remove the echo off from the batch, so you can see the processing files.
-q flag is for quite, will not output results after each file. Hence remove echo off.
-nodate The original date on the png will not be updated. Nice to know when a file was added to my collection, not the last touch date.
-pngpalette=40 This change corresponds to using Lossy - Strong (palette) in the GUI interface.

Benefits of these changes:
The GUI interface can be used for speed when time is short at the expense of processor overload. Multi-threading is a bitch sometimes.
When the gui crashes out, then the batch script can be used on the leftover stuff that did not compress. Single threaded process.
If the PNG does not compress further, you are at the best case.

Edit further investigation:
If the bat file is located in the root of a bunch of directories, there is no need to recursive the directories. The bat will flow to them all. Multi-threading is on by default unless you use the -nomulti switch. Multi-thread can remain on. This multi-thread is preformed on a single file. Does not max out all the threads. aka bang the crap out faster. Also by using the bat the crash out problem of the GUI is avoided. All files will be best case no redo is needed.

As long as the bat is used only PNG will be effected. There are a ton of other -no switches relating to other files and processes.
 

Users who are viewing this thread

Top