Urgent! Recognize Bit-Depth.

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
andrefaria
Posts: 3
Joined: 2013-10-17T10:39:09-07:00
Authentication code: 6789

Urgent! Recognize Bit-Depth.

Post by andrefaria »

I have a directory with many different types of images. They have Bit-Depth of 1 bit, and 24 other other 8.
I would like to put in a command where ONLY negative images with 1 bit.
Can anyone help me?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Urgent! Recognize Bit-Depth.

Post by fmw42 »

You have to extract that from the IM verbose information. The string formats "%z" and "%[depth]" only show 8 vs 16, etc

# create depth 1 image

convert rose: -threshold 50% rose_t50.png
identify -verbose rose_t50.png
...
Depth: 8/1-bit

In unix, this could get extracted by

depth=`convert rose_t50.png -verbose info: | sed -n 's/^ Depth:[^0-9]*\(.*\)-bit$/\1/p' | tr "/" " " | cut -d\ -f2`
echo "$depth"
1

depth=`convert rose: -verbose info: | sed -n 's/^ Depth:[^0-9]*\(.*\)-bit$/\1/p' | tr "/" " " | cut -d\ -f2`
echo "$depth"
8
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Urgent! Recognize Bit-Depth.

Post by snibgo »

An equivalent in Windows, using just Windows tools, is:

Code: Select all

for /F "usebackq tokens=1-2 delims=Depth-bit:/ " %%L ^
in (`%IM%convert -verbose %1 info:^|findstr "Depth"`) do (
set DEPTH=%%M
if "!DEPTH!"=="" set DEPTH=%%L
)

echo Depth of %1 is %DEPTH% bits.
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Urgent! Recognize Bit-Depth.

Post by snibgo »

@andrefaria: See the thread viewtopic.php?f=2&t=24291 for a new feature that will help.
snibgo's IM pages: im.snibgo.com
Post Reply