Convert entire folder to 8-bit

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
acoustic7
Posts: 14
Joined: 2013-08-06T14:32:05-07:00
Authentication code: 6789

Convert entire folder to 8-bit

Post by acoustic7 »

I have seen something like this question in a few other places around the site.
I need to convert a folder of pngs to 8-bit.

convert original.png -auto-level -depth 8 -define quantum:format=unsigned -type grayscale test.png

works for an individual photo,

and I tried mogrify -format png -depth 8 *.png on the directory but I don't think it worked. Both of those commands I found on other topics. Anyone have any idea how to use mogrify (i assume) to make all of these images 8-bit?
Last edited by acoustic7 on 2013-08-13T13:59:11-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Confert entire folder to 8-bit

Post by fmw42 »

You need the png equivalent of this -define to be able to set the output in mogrify to PNG8 (PNG24 and PNG32). viewtopic.php?f=1&t=23875#p101575

I have suggested it already to the png developer, but have not heard back. Perhaps it will make it into the next version of IM, if he has not already done so.

In the mean time, try adding -type palette and or -colors 255 rather than grayscale in your mogrify command. That may work already. I do not think the quantumformat is something that either mogrify or PNG knows about. So it is likely useless.
Last edited by fmw42 on 2013-08-13T14:01:28-07:00, edited 2 times in total.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Confert entire folder to 8-bit

Post by glennrp »

try "-colors 255" which should give you an 8-bit indexed PNG.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert entire folder to 8-bit

Post by snibgo »

acoustic7 wrote:I need to convert a folder of pngs to 8-bit.
What do you mean? 8 bits per pixel per channel, or 8 bits total per pixel?
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert entire folder to 8-bit

Post by fmw42 »

8-bits total (that is type palette using a color map)

if you want 8bits per channel and are using Q16 IM compile, then -depth 8 should be enough.
acoustic7
Posts: 14
Joined: 2013-08-06T14:32:05-07:00
Authentication code: 6789

Re: Convert entire folder to 8-bit

Post by acoustic7 »

Thank you all for the responses!

I tried a sort of hybrid of the two commands before seeing these responses and it seems to have worked. For anyone curious, I did:

mogrify -format png -auto-level -depth 8 -define quantum:format=unsigned -type grayscale *.png

and as I said, it seems to have worked.

Thanks for the other suggestions though, I'm going to have to do this with some more images in the future, and chances are good that they won't work with the same command that these did, so -color255 and-type palette will probably come in handy.

thank you!!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert entire folder to 8-bit

Post by snibgo »

I had missed the fact that this is greyscale, so there is only one channel. Hence "bits per pixel" and "bits per channel per pixel" are the same.
snibgo's IM pages: im.snibgo.com
Post Reply