Short code to save an image! as a color image in PPM binary (P6) format. It's mostly useful for interacting with the Netpbm tools. No alpha information is saved, use 'alpha-to-pgm too (in one-liner-image-to-pgm.r) if you need it.
2. Usage
to-ppm value (image!)
3. Example
REBOL 2:
write/binary %imageTest.ppm to-ppm make image! [320x256 255.0.0]
REBOL3 always write in binary, so:
write %imageTest.ppm to-ppm make image! [320x256 255.0.0]
4. Commented Code
to-ppm: func [
"Converts an image to a PPM binary file format"
value [image!] "Image source"
] [
; equivalent to "to-binary rejoin" : we want a binary! resul
join #{} [
; the binary PPM file header, followed by a <space>
"P6 "
; the image size, in the form width <space> height
replace form value/size "x" " "
; a <space>, the max component value, and a <newline>
" 255^(0A)"
: the image data as RGB bytes sequences
value/rgb
]
]