Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Batch conversion from JPG to PNG
#1
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?

Best regards.
Reply
#2
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.
Reply
#3
(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.

Thanks for answering!
Reply
#4
Here is one example.

Batch converted is 302k, manual converted is 258k, the difference is huge.


Attached Files Thumbnail(s)
           
Reply
#5
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
Code:
magick mogrify -flatten -quality 100  -format png  *.jpg
Not quite as small as Gimp but close.


Attached Files
.zip   advanced_batch_remove_alpha.zip (Size: 2.85 KB / Downloads: 137)
Reply
#6
Thanks for the reply.

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.
Reply
#7
Quote:..Removing alpha channel for my original (copyrighted) files did not produce large effect...

That is not exactly what I meant. The original files are jpeg and therefore do not have an alpha channel.

Batch convert to png first then apply that batch-remove-alpha plugin to those (png) files.

There is another possibly better batch converter for your files XnViewMP which has a batch convert facility.
Reply
#8
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.
Reply
#9
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.
Reply
#10
If you use 32-bit precision images in Gimp, the PNG export uses the 16-bit PNG variant by default, which of course nearly doubles the size. Either
  • Check your options and make sure that you are not "promoting" your image to floating point when loading (Edit>Preferences>Image import and export).
  • Export a PNG, choose 8bpc RGBA as the output format (instead of "automatic pixelformat"), and click "Save defaults.
Reply


Forum Jump: