I want to convert series of grayscale textual pictures from JPG to PNG. Because of large number of pictures, I am using batching with BIMP.
Starting with 262k JPG file
- if I change manually I get 196k PNG file,
- if I change by batch I get 292k PNG file.
The difference is huge and I cannot figure what is wrong. The one logical explanation I could come up is that when I use batch, I cannot set pixelformat. In manual change I use default "automatic pixelformat".
Is my conclusion correct? Is there a way I could convert to PNG by batch and get the same result?
Can you post one of your greyscale textual jpeg images. Are these scanned pages perhaps.
It is unusual for a png to be smaller in size than the jpeg. Might be some property of the jpeg. Could be the manual conversion png is indexed. and the batch conversion not.
(09-16-2020, 06:45 PM)rich2005 Wrote: Can you post one of your greyscale textual jpeg images. Are these scanned pages perhaps.
It is unusual for a png to be smaller in size than the jpeg. Might be some property of the jpeg. Could be the manual conversion png is indexed. and the batch conversion not.
Yes, it is scanned text.
It is copyrighted so I should not really not post it, just in case.
I will test another scanned page tomorrow and be back with information.
09-17-2020, 10:31 AM (This post was last modified: 09-17-2020, 10:31 AM by rich2005.
Edit Reason: typo
)
Thanks for the example.
I can see the problem, the BIMP png's have an alpha channel which adds to the size. I tried all ways but I can not see any way to get BIMP not to add an alpha channel. It must be a bug, even goes back to older (1.18) versions. I will post a bug report but not much activity on the BIMP front these days.
Two options:
Use BIMP to batch produce the pngs. A second operation using the attached plugin advanced_batch_remove_alpha.py to remove the alpha channel from those files. From a test that gives the same size as exporting one-by-one.
or
Not Gimp, use ImageMagic https://imagemagick.org and a command line in the file folder
Removing alpha channel for my original (copyrighted) files did not produce large effect.
However, using your other suggestion, I converted pictures to indexed mode before converting them to PNG. That makes a larger difference even for 256 colors and for 128 gives the result that is comparable to manual saving to PNG. I was unable to produce exactly the same result with either your script or indexed mode procedure.
09-17-2020, 05:58 PM (This post was last modified: 09-17-2020, 05:59 PM by pygmalion.)
Well, the whole original process is actually scanned file - convert to grayscale - curve correction - reduce size - convert to PNG
By testing I determined that convert to PNG part makes huge difference - manual procedure gives much smaller document than batch procedure.
So I tried scanned file - convert to grayscale - curve correction - reduce size - convert to PNG - remove alpha
which gives better result, but not as good as manual procedure.
However scanned file - convert to grayscale - curve correction - reduce size - convert to indexed - convert to PNG - (remove alpha)
gives a better result, depending on the number of colors. Interestingly, in this procedure, remove alpha makes no difference.
09-17-2020, 06:14 PM (This post was last modified: 09-17-2020, 06:15 PM by rich2005.
Edit Reason: typo
)
As long as you get a result and are happy with it.
as the thread title "Batch conversion from JPG to PNG"
Whichever way you do your corrections you decided to end up with a jpeg. Is that your reduce size? That only reduces the file size by a lossy-jpeg compression. Nothing to do with the image size.
As my previous remarks, for whatever reason BIMP adds an alpha channel to the png output*. You can remove alpha to your hearts content but when the end of the pipeline is the BIMP procedure to write a png file you get an alpha channel. I know I tried various this morning for a different result.
* I did write a bug report but this is probably a 'catch-all' default. There will be some conversions where an alpha channel is required.