Convert -resize but keep channel depth for blue at 2 bits

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
cpc664
Posts: 3
Joined: 2017-01-03T05:24:33-07:00
Authentication code: 1151

Convert -resize but keep channel depth for blue at 2 bits

Post by cpc664 »

Hello,

using convert v6.8.9-9, I want to resize an image with these characteristics (source is a PNG of an Amstrad CPC screen capture) :

Colorspace: sRGB
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 2-bit

The result with -resize 21% -depth 8 -type palette comes with a blue channel depth of 8bit.

How can I keep a channel depth for blue at 2 bits ? Thanks.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert -resize but keep channel depth for blue at 2 bits

Post by fmw42 »

You may have to resize, separate channels and set the depth as required, then combine the channels again.

This seems to work for me (unix syntax)

Code: Select all

convert rose: -depth 8 -resize 200% -separate \
\( -clone 0 -depth 8 \) \
\( -clone 1 -depth 8 \) \
\( -clone 2 -depth 2 \) \
-delete 0-2 -combine -set colorspace sRGB \
rose.png

Code: Select all

identify -verbose rose.png
Depth: 8-bit
Channel depth:
red: 8-bit
green: 8-bit
blue: 2-bit
cpc664
Posts: 3
Joined: 2017-01-03T05:24:33-07:00
Authentication code: 1151

Re: Convert -resize but keep channel depth for blue at 2 bits

Post by cpc664 »

Thanks, it works but the resulting image is bigger.

My primary goal was to have a lesser resolution image with a smaller file size for web use.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert -resize but keep channel depth for blue at 2 bits

Post by snibgo »

cpc664 wrote:My primary goal was to have a lesser resolution image with a smaller file size for web use.
For PNG files, I suggest you use the pngcrush program.
snibgo's IM pages: im.snibgo.com
cpc664
Posts: 3
Joined: 2017-01-03T05:24:33-07:00
Authentication code: 1151

Re: Convert -resize but keep channel depth for blue at 2 bits

Post by cpc664 »

At the moment I use a small script with optipng and advpng :

#! /bin/sh
optipng -i 0 -o 7 $1
advpng -z -4 -i 50 $1
Post Reply