It is trivial to generate P5 PGM / P6 PPM using imagemagick, using simply
$ convert -depth 12 -size 512x512 xc:white white12.pgm
$ convert -depth 12 -size 512x512 xc:white white12.ppm
Which correctly gives:
% head -3 white12.ppm white12.pgm
==> white12.ppm <==
P6
512 512
4095
==> white12.pgm <==
P5
512 512
4095
Now I am struggling to get PAM: P7 Grayscale working, all I could find is:
$ convert -depth 12 -size 512x512 xc:white white12.pam
which gives the RGB
one:
% head -7 white12.pam
P7
WIDTH 512
HEIGHT 512
DEPTH 3
MAXVAL 4095
TUPLTYPE RGB
ENDHDR
How can I generate the GRAYSCALE
PAM one ?
I did report a bug upstream, maybe there is something bogus in my imagemagick version:
CodePudding user response:
In Imagemagick, to create text format NetPBM files, add -compress none.
convert -depth 12 -size 512x512 xc:white -compress none white12.pam
head -7 white12.pam
P7
WIDTH 512
HEIGHT 512
DEPTH 3
MAXVAL 4095
TUPLTYPE RGB
ENDHDR
CodePudding user response:
I think there is a bug here in ImageMagick. This might be a workaround:
magick -depth 12 -size 512x512 gradient: -colorspace gray -compress none pgm:- | awk '
NR==2 {w=$1; h=$2} # pick up and save height and width on line 2
NR<4 {next} # ignore lines 1-3
NR==4 {printf("P7\nWIDTH %d\nHEIGHT %d\nDEPTH 1\nMAXVAL 4096\nTUPLTYPE GRAYSCALE\nENDHDR\n", w,h);}
1 # pass remaining lines through unchanged' > result.pam
That produces this:
P7
WIDTH 512
HEIGHT 512
DEPTH 1
MAXVAL 4096
TUPLTYPE GRAYSCALE
ENDHDR
65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535 65535