Using the data storage type defined on this page for raster images, delegate writing a JPEG file through a pipe using the output_ppm function defined on this other page.

There are various utilities that can be used for this task, for example: cjpeg (package "jpeg-progs" on Linux), ppmtojpeg (package "netpbm" on Linux), convert (from ImageMagick, multi-platform).

-- demo\rosetta\Bitmap_PPM_conversion_through_a_pipe.exw
without js -- file i/o, system_exec(), pipes[!!]
include builtins\pipeio.e
include builtins\serialize.e
include ppm.e -- read_ppm()

sequence pipes = repeat(0,3)
pipes[PIPEIN] = create_pipe(INHERIT_WRITE)

-- Create the child process, with replacement stdin. 
string cmd = sprintf("%s viewppm -save test.jpg",{get_interpreter(true)})
atom hProc = system_exec(cmd, 12, pipes),
     hPipe = pipes[PIPEIN][WRITE_PIPE]

sequence img = serialize(read_ppm("Lena.ppm",bFlat:=true))
if not write_to_pipe(hPipe,img) then crash("error") end if

-- Close the pipe handle so the child process stops reading. 
--hPipe = close_handles(hPipe)
pipes = close_handles(pipes) -- (may as well do the lot)

?"done"
{} = wait_key()
