Page 1 of 1

How can imagemagick determine the bit depth of a image need

Posted: 2018-12-04T22:54:32-07:00
by tczf1128
I have a png image which is 8 bit depth, when I scale it to 80%, the bit depth become 16.

convert -resize 80% 58a40d9d85367.png 58a40d9d85367.im.png

Image

Re: How can imagemagick determine the bit depth of a image need

Posted: 2018-12-05T00:15:59-07:00
by fmw42
Your syntax is wrong, but IM 6 is forgiving. IM 7 will not be forgiving. ImageMagick does not follow the usual Unix syntax, but expects you to read a raster input image before applying processing commands to it, and then write the output.

See https://imagemagick.org/Usage/basics/#why

When I do (IM 6.9.10.15 Q16 or IM 7.0.8.15 Q16 HDRI Mac OSX Sierra):

Code: Select all

convert 58a40d9d85367.png -resize 80% tmp.png
identify -verbose tmp.png
Image: tmp.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 640x640+0+0
Units: Undefined
Colorspace: sRGB
Type: TrueColorAlpha
Base type: Undefined
Endianess: Undefined
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 8-bit
alpha: 8-bit
....

It is still 8-bit depth. What is your IM version and platform? Please always provide that when asking questions.

____________________


Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
https://imagemagick.org/script/porting.php#cli

Re: How can imagemagick determine the bit depth of a image need

Posted: 2018-12-05T02:39:26-07:00
by tczf1128
I try your command both in macos and centos7.2, both reuslt png is 16 bit depth

$ uname -a
Darwin MBA.local 18.2.0 Darwin Kernel Version 18.2.0: Fri Oct 5 19:41:49 PDT 2018; root:xnu-4903.221.2~2/RELEASE_X86_64 x86_64
$ convert -version
Version: ImageMagick 7.0.8-12 Q16 x86_64 2018-10-15 https://imagemagick.org
Copyright: © 1999-2018 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff webp xml zlib

Image: tmp.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 640x640+0+0
Units: Undefined
Colorspace: sRGB
Type: TrueColorAlpha
Base type: Undefined
Endianess: Undefined
Depth: 16-bit
Channel depth:
Red: 16-bit
Green: 16-bit
Blue: 16-bit
Alpha: 16-bit

Re: How can imagemagick determine the bit depth of a image need

Posted: 2018-12-05T02:44:29-07:00
by tczf1128
It result in a bigger size png when resize.

and version in centos7.2
Version: ImageMagick 7.0.8-12 Q16 x86_64

$ uname -a
Linux 3.10.0-862.2.3.el7.x86_64 #1 SMP Wed May 9 18:05:47 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
$ identify -verbose tmp.png
Image: tmp.png
Format: PNG (Portable Network Graphics)
Mime type: image/png
Class: DirectClass
Geometry: 640x640+0+0
Units: Undefined
Colorspace: sRGB
Type: TrueColorAlpha
Base type: Undefined
Endianess: Undefined
Depth: 16-bit
Channel depth:
Red: 16-bit
Green: 16-bit
Blue: 16-bit
Alpha: 16-bit
Channel statistics:

Re: How can imagemagick determine the bit depth of a image need

Posted: 2018-12-05T11:13:16-07:00
by fmw42
Can you try upgrading to the latest version. If not add -depth 8 to your command.

Re: How can imagemagick determine the bit depth of a image need

Posted: 2018-12-05T21:47:46-07:00
by tczf1128
It works when I upgrade imagemagick from 7.0.8-12 to 7.0.8-14, but the size of resized image is bigger than the original one.

Re: How can imagemagick determine the bit depth of a image need

Posted: 2018-12-05T22:16:34-07:00
by fmw42
On IM 7.0.8.15 Q16 Mac OSX Sierra, the result is smaller by about half (125K for the result vs 216K for the original)

Code: Select all

magick 58a40d9d85367.png -resize 80% tmp.png
magick identify 58a40d9d85367.png tmp.png
58a40d9d85367.png PNG 800x800 800x800+0+0 8-bit sRGB 216289B 0.000u 0:00.000
tmp.png PNG 640x640 640x640+0+0 8-bit sRGB 124812B 0.000u 0:00.000

Re: How can imagemagick determine the bit depth of a image need

Posted: 2018-12-05T22:24:23-07:00
by tczf1128
try this png
http://test-1257746263.picsh.myqcloud.c ... e7c984.png

Code: Select all

convert  7a063c32e5c29a16fda4c02842e7c984.png -resize 80% tmp.png
-rw-r--r-- 1 tczf staff 45K 12 3 22:44 7a063c32e5c29a16fda4c02842e7c984.png
-rw-r--r--@ 1 tczf staff 211K 12 3 19:31 58a40d9d85367.png

Re: How can imagemagick determine the bit depth of a image need

Posted: 2018-12-06T00:00:11-07:00
by tczf1128
And another question.
16 bit depth png to be resized 60%, its depth still 16 bit?
I try this imagehttp://test-1257746263.picsh.myqcloud.c ... Snap20.png and the result is 16 depth

Re: How can imagemagick determine the bit depth of a image need

Posted: 2018-12-06T00:05:29-07:00
by fmw42
tczf1128 wrote:
2018-12-05T22:24:23-07:00
try this png
http://test-1257746263.picsh.myqcloud.c ... e7c984.png

Code: Select all

convert  7a063c32e5c29a16fda4c02842e7c984.png -resize 80% tmp.png
-rw-r--r-- 1 tczf staff 45K 12 3 22:44 7a063c32e5c29a16fda4c02842e7c984.png
-rw-r--r--@ 1 tczf staff 211K 12 3 19:31 58a40d9d85367.png
This input image is 8-bit palette (pseudo color), when you resize you get more colors introduced which in this case is more the 256 colors so the result is converted to 24-bit color. To prevent this, write it as

Code: Select all

convert  7a063c32e5c29a16fda4c02842e7c984.png -resize 80% PNG8:tmp.png
To convert back to palette type.

Re: How can imagemagick determine the bit depth of a image need

Posted: 2018-12-06T00:08:51-07:00
by fmw42
tczf1128 wrote:
2018-12-06T00:00:11-07:00
And another question.
16 bit depth png to be resized 60%, its depth still 16 bit?
I try this imagehttp://test-1257746263.picsh.myqcloud.c ... Snap20.png and the result is 16 depth
16-bit images will convert to 16-bit images unless you specify -density 8

try

Code: Select all

convert LeftSnap20.png -resize 80% -depth 8 result.png

Re: How can imagemagick determine the bit depth of a image need

Posted: 2018-12-06T00:19:07-07:00
by tczf1128
So how can I know a 16 depth png can convert a 8 bit depth png without distortion. I'm using the magickWand api

Re: How can imagemagick determine the bit depth of a image need

Posted: 2018-12-06T00:21:22-07:00
by fmw42
tczf1128 wrote:
2018-12-06T00:19:07-07:00
So how can I know a 16 depth png can convert a 8 bit depth png without distortion. I'm using the magickWand api
You will always lose some quality going from 16-bit to 8-bit, but it may not be visually noticeable. You have to decide what you want to do here.

Re: How can imagemagick determine the bit depth of a image need

Posted: 2018-12-06T00:56:42-07:00
by tczf1128
Thanks so much