```{index} single: PDL::IO::Pnm ``` # PDL::IO::Pnm ```{pperl-module-badges} PDL::IO::Pnm ``` Reading and writing images in the PNM formats: PBM, PGM and PPM. ```perl use PDL; use PDL::IO::Pnm; use File::Temp qw(tempdir); my $file = tempdir(CLEANUP => 1) . "/img.pgm"; wpnm(byte([[0, 128], [255, 64]]), $file, 'PGM', 1); my $im = rpnm($file); print $im->flat, " ", $im->type, "\n"; # [0 128 255 64] byte ``` `rpnm($file)` reads a PBM, PGM or PPM file, raw or ASCII, into an ndarray - 2-D for grey levels, `(3, width, height)` for colour - and `wpnm($im, $file, $format, $raw)` writes one. `pnminraw`, `pnminascii` and `pnmout` are the kernels underneath, reading and writing through a Perl filehandle. This is PDL::IO::Pnm of PDL 2.104: upstream's Perl, unchanged, over PDL's own kernels run by pperl's engine. PDL::IO::Pic uses it, so `use PDL` loads it.