piman314
piman314

Reputation: 5355

Setting number of channels in imagemagick convert

I've got a PDF with multiple pages that I have used pdftk and imagemagick to split and convert into png's using the below script. Problem is that some of the pages of my PDF are black and white and others are colour, and this means that some of my images are saving as single channel and the rest are three channel. This is causing me issues down the line, and would be best to fix here.

Does anyone know how I can force my black and white images to have three channels, ideally using convert?

#!/bin/bash
for i in {1..105}
do
    pdftk FNAME-12A.pdf cat $i output FNAME-12A_$i.pdf
    convert -density 128 FNAME-12A_$i.pdf -quality 100 -channel RGB FNAME-12A_$i.png
done

Upvotes: 4

Views: 1566

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207475

Prefix the output filename with PNG24:

convert something ... PNG24:output.png

For the sake of completeness and future reference, you can also use the following to force PNG variants:

  • PNG8: force palettised image
  • PNG24: force 3 channel, 8-bits each
  • PNG32: force 4 channel, RGBA, 8-bits each
  • PNG48: force 3 channel, 16-bits each
  • PNG64: force 4 channel, RGBA, 16-bits each

Upvotes: 8

Related Questions