Bitmap/PPM conversion through a pipe: Difference between revisions

Line 187:
WriteLine[process,"Quit[]"];
];</lang>
 
=={{header|Nim}}==
We use "convert" command from ImageMagick and "pnmtojpeg" command from Netpbm. The first command allows to specify the output file name, the second writes to stdout and, so, we have to use a redirection. Thus, the way to launch the process is slightly different.
 
<lang Nim>import bitmap
import ppm_write
import osproc
 
# Build an image.
var image = initImage(100, 50)
image.fill(color(255, 0, 0))
for row in 10..20:
for col in 0..<image.w:
image[col, row] = color(0, 255, 0)
for row in 30..40:
for col in 0..<image.w:
image[col, row] = color(0, 0, 255)
 
# Launch ImageMagick "convert".
# Input is taken from stdin and result written in "output1.jpeg".
var p = startProcess("/usr/bin/convert", args = ["ppm:-", "output1.jpeg"])
let stream = p.inputStream()
image.writePPM(stream)
p.close()
 
# Launch Netpbm "pnmtojpeg".
# Input is taken from stdin and output sent to "output2.jpeg".
p = startProcess("/usr/bin/pnmtojpeg >output2.jpeg", options = {poEvalCommand})
let inStream = p.inputStream()
image.writePPM(inStream)
p.close()</lang>
 
== {{Header|OCaml}} ==
Anonymous user