Script Library: 1238 scripts
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
View scriptLicenseDownload documentation as: HTML or editable
Download scriptHistoryOther scripts by: vincentecuye

Documentation for: oneliner-image-to-ppm.r



Author: Vincent Ecuyer
Date: 30-Jan-2013


1. Purpose
2. Usage
3. Example
4. Commented Code

1. Purpose

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


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
MakeDoc2 by REBOL- 29-Jan-2013