It is currently Sat Jun 22, 2024 8:42 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: converting 32 bit images to 8 bit using batch script
PostPosted: Sun Jan 24, 2021 7:59 pm  (#1) 
Offline
New Member

Joined: Jan 24, 2021
Posts: 4
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 :)

_________________


(\_/) 
( •_•)
*/ ¬ ¬\ greetings!



Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: converting 32 bit images to 8 bit using batch script
PostPosted: Mon Jan 25, 2021 5:13 am  (#2) 
Offline
GimpChat Member

Joined: Mar 04, 2011
Posts: 2435
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 4398 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

_________________
Image
Top
 Post subject: Re: converting 32 bit images to 8 bit using batch script
PostPosted: Mon Jan 25, 2021 11:09 am  (#3) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4750
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

_________________
Image


Top
 Post subject: Re: converting 32 bit images to 8 bit using batch script
PostPosted: Mon Jan 25, 2021 5:20 pm  (#4) 
Offline
New Member

Joined: Jan 24, 2021
Posts: 4
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

_________________


(\_/) 
( •_•)
*/ ¬ ¬\ greetings!



Top
 Post subject: Re: converting 32 bit images to 8 bit using batch script
PostPosted: Mon Jan 25, 2021 5:26 pm  (#5) 
Offline
New Member

Joined: Jan 24, 2021
Posts: 4
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

_________________


(\_/) 
( •_•)
*/ ¬ ¬\ greetings!



Top
 Post subject: Re: converting 32 bit images to 8 bit using batch script
PostPosted: Tue Jan 26, 2021 3:16 pm  (#6) 
Offline
New Member

Joined: Jan 24, 2021
Posts: 4
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

_________________


(\_/) 
( •_•)
*/ ¬ ¬\ greetings!



Top
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Batch export all opened images script for GIMP [Update]

13

No new posts Attachment(s) Seeking Help with First Multi-File Batch Script

9

No new posts Batch Create Layers

2

No new posts Attachment(s) Problem with David's Batch Processor plugin

22

No new posts ofnut colormap-to-layer plugin + BATCH

0



* Login  



Powered by phpBB3 © phpBB Group