Bitmap/PPM conversion through a pipe: Difference between revisions

Rename Perl 6 -> Raku, alphabetize, minor clean-up
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
Line 46:
 
In order to make it working, you must link it with the raster image functions given by the codes [[Bresenham's_line_algorithm#C|here]] and [[Basic_bitmap_storage#C|here]]
 
=={{header|Go}}==
{{works with|Go weekly.2011-12-14}} (Go 1 should be close)
Line 205 ⟶ 206:
;;</lang>
 
=={{header|Perl 6PicoLisp}}==
<lang PicoLisp># Create an empty image of 120 x 90 pixels
(setq *Ppm (make (do 90 (link (need 120)))))
 
# Fill background with green color
(ppmFill *Ppm 0 255 0)
 
# Draw a diagonal line
(for I 80 (ppmSetPixel *Ppm I I 0 0 0))
 
# Write to "img.jpg" through a pipe
(ppmWrite *Ppm '("convert" "-" "img.jpg"))</lang>
 
=={{header|Python}}==
<lang Python>
"""
Adapted from https://stackoverflow.com/questions/26937143/ppm-to-jpeg-jpg-conversion-for-python-3-4-1
Requires pillow-5.3.0 with Python 3.7.1 32-bit on Windows.
Sample ppm graphics files from http://www.cs.cornell.edu/courses/cs664/2003fa/images/
"""
 
from PIL import Image
 
im = Image.open("boxes_1.ppm")
im.save("boxes_1.jpg")
</lang>
Does not need to pipe through a conversion utility
because the Pillow module does the conversion.
 
=={{header|Racket}}==
<lang racket>
(define (ppm->jpeg bitmap [jpg-file "output"] [quality 75])
(define command (format "convert ppm:- -quality ~a jpg:~a.jpg" quality jpg-file))
(match-define (list in out pid err ctrl) (process command))
(bitmap->ppm bitmap out)
(close-input-port in)
(close-output-port out))
 
(ppm->jpeg bm)</lang>
 
=={{header|PicoLispRaku}}==
(formerly Perl 6)
<lang perl6>#!/usr/bin/env perl6
 
Line 248 ⟶ 290:
<pre>file output_piped.jpg
output_piped.jpg: JPEG image data, JFIF standard 1.01, aspect ratio, density 1x1, segment length 16, baseline, precision 8, 125x125, frames 3</pre>
 
=={{header|PicoLisp}}==
<lang PicoLisp># Create an empty image of 120 x 90 pixels
(setq *Ppm (make (do 90 (link (need 120)))))
 
# Fill background with green color
(ppmFill *Ppm 0 255 0)
 
# Draw a diagonal line
(for I 80 (ppmSetPixel *Ppm I I 0 0 0))
 
# Write to "img.jpg" through a pipe
(ppmWrite *Ppm '("convert" "-" "img.jpg"))</lang>
 
=={{header|Python}}==
<lang Python>
"""
Adapted from https://stackoverflow.com/questions/26937143/ppm-to-jpeg-jpg-conversion-for-python-3-4-1
Requires pillow-5.3.0 with Python 3.7.1 32-bit on Windows.
Sample ppm graphics files from http://www.cs.cornell.edu/courses/cs664/2003fa/images/
"""
 
from PIL import Image
 
im = Image.open("boxes_1.ppm")
im.save("boxes_1.jpg")
</lang>
Does not need to pipe through a conversion utility
because the Pillow module does the conversion.
 
=={{header|Racket}}==
<lang racket>
(define (ppm->jpeg bitmap [jpg-file "output"] [quality 75])
(define command (format "convert ppm:- -quality ~a jpg:~a.jpg" quality jpg-file))
(match-define (list in out pid err ctrl) (process command))
(bitmap->ppm bitmap out)
(close-input-port in)
(close-output-port out))
 
(ppm->jpeg bm)</lang>
 
=={{header|Ruby}}==
10,343

edits