GIMP Chat
http://gimpchat.com/

converting 32 bit images to 8 bit using batch script
http://gimpchat.com/viewtopic.php?f=9&t=19089
Page 1 of 1

Author:  littlenellie [ Sun Jan 24, 2021 7:59 pm ]
Post subject:  converting 32 bit images to 8 bit using batch script

Hi,

I'd like to convert a large number of 32 bit png images (single layer) to 8 bit gray png (single layer).

I've not used Script-Fu or Python with GIMP before, but can't see anything in the Procedure Browser that has a parameter for specifying bit depth. Is that possible with scripting?

I'm using GIMP 2.10.20.

Many thanks :)

Author:  rich2005 [ Mon Jan 25, 2021 5:13 am ]
Post subject:  Re: converting 32 bit images to 8 bit using batch script

The easiest way for a large number of images is use an existing plug-in BIMP see: https://alessandrofrancesconi.it/projects/bimp/ where you can add various procedures including a convert to grayscale.

Attachment:
bimp.jpg
bimp.jpg [ 126.86 KiB | Viewed 4421 times ]


Edit: This issue came up one time. Using BIMP and png format an alpha channel is added. No way to avoid this with BIMP as the export is the final function.

If the alpha channel is a problem (larger file size etc) then this is a batch plugin for removing the alpha channel following on from BIMP.
https://github.com/samvanemelen/GIMP-pl ... ansparency

Edit again ;)maybe the gimp procedure if you want to write your own batch file is
pdb.gimp_image_convert_grayscale(image)
..but as you say not bitdepth. As an example attached a simple python script that does that for an open image.

Attachments:
to_gs.zip [389 Bytes]
Downloaded 128 times

Author:  ofnuts [ Mon Jan 25, 2021 11:09 am ]
Post subject:  Re: converting 32 bit images to 8 bit using batch script

littlenellie wrote:
Hi,

I'd like to convert a large number of 32 bit png images (single layer) to 8 bit gray png (single layer).

I've not used Script-Fu or Python with GIMP before, but can't see anything in the Procedure Browser that has a parameter for specifying bit depth. Is that possible with scripting?

I'm using GIMP 2.10.20.

Many thanks :)


Very likely much easier to do in ImageMagick (designed to be used in shell scripts). See

https://legacy.imagemagick.org/Usage/fo ... ng_formats

Author:  littlenellie [ Mon Jan 25, 2021 5:20 pm ]
Post subject:  Re: converting 32 bit images to 8 bit using batch script

rich2005 wrote:
The easiest way for a large number of images is use an existing plug-in BIMP see: (snip, snip) where you can add various procedures including a convert to grayscale.

....(snip, snip)

Edit: This issue came up one time. Using BIMP and png format an alpha channel is added. No way to avoid this with BIMP as the export is the final function.

If the alpha channel is a problem (larger file size etc) then this is a batch plugin for removing the alpha channel following on from BIMP.
(snip, snip)

Edit again ;)maybe the gimp procedure if you want to write your own batch file is
pdb.gimp_image_convert_grayscale(image)
..but as you say not bitdepth. As an example attached a simple python script that does that for an open image.

Great stuff, that's saved me a lot of time poking around trying to find something that didn't exist ;) I might come back to the python option, so thanks for the example script - very useful. Cheers :)

:tyspin

Author:  littlenellie [ Mon Jan 25, 2021 5:26 pm ]
Post subject:  Re: converting 32 bit images to 8 bit using batch script

ofnuts wrote:
Very likely much easier to do in ImageMagick (designed to be used in shell scripts). (snip, snip)

*facepalm* it hadn't even occurred to me to look for an alternative bit of software :oops: That is an excellent suggestion, and good to know that about ImageMagick as I've never used it. Thank you! :bigthup :bigthup :bigthup

Author:  littlenellie [ Tue Jan 26, 2021 3:16 pm ]
Post subject:  Re: converting 32 bit images to 8 bit using batch script

Hey,

So for anyone looking to do this, Ofnuts's ImageMagick solution worked brilliantly.

The steps that worked for me:
* I downloaded the Windows version (I'm running Win10) of ImageMagick
* copied the *.png files that I wanted to convert into a separate folder
* opened a DOS Command Prompt window and navigated to the folder with the images in
* ran the following code (which creates a *.bat file in the same folder):
for %f in (*.png) do echo magick %f -depth 8 %f >>set_files_to_8_bit.bat

* run the set_files_to_8_bit.bat file.
* Files converted, job done. :yes

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/