Bitmap/PPM conversion through a pipe: Difference between revisions

→‎{{header|Tcl}}: + standard ML
m (→‎{{header|Raku}}: Fix code: Perl 6 --> Raku)
(→‎{{header|Tcl}}: + standard ML)
Line 333:
image.save_as_jpeg('file.jpg')</lang>
 
=={{header|Standard ML}}==
<lang Standard ML>
val useOSConvert = fn ppm =>
let
val img = String.translate (fn #"\"" => "\\\""|n=>str n ) ppm ;
val app = " convert - jpeg:- "
val fname = "/tmp/fConv" ^ (String.extract (Time.toString (Posix.ProcEnv.time()),7,NONE) );
val shellCommand = " echo \"" ^ img ^ "\" | " ^ app ;
val me = ( Posix.FileSys.mkfifo
(fname,
Posix.FileSys.S.flags [ Posix.FileSys.S.irusr,Posix.FileSys.S.iwusr ]
) ;
Posix.Process.fork ()
) ;
in
if (Option.isSome me) then
let
val fin =BinIO.openIn fname
in
( Posix.Process.sleep (Time.fromReal 0.1) ;
BinIO.inputAll fin before
(BinIO.closeIn fin ; OS.FileSys.remove fname )
)
end
else
( OS.Process.system ( shellCommand ^ " > " ^ fname ^ " 2>&1 " ) ;
Word8Vector.fromList [] before OS.Process.exit OS.Process.success
)
end;
</lang>
call and return value
<lang Standard ML>
useOSConvert "/* XPM */ static char * new[] = {\"7 1 2 1\",\" c white\",\". c black\",\" . \"};" ;
val it =
fromList[0wxFF, 0wxD8, 0wxFF, 0wxE0, 0wx0, 0wx10, 0wx4A, 0wx46, 0wx49,
0wx46, ...]: vector
</lang>
=={{header|Tcl}}==
Referring to [[Write ppm file#Tcl]] and [[Basic bitmap storage#Tcl]]
Anonymous user