@@ -0,0 +1,1308 @@
+'''%0A  This module provides routines for writing PGM/PBM images in Python (3.x)%0A  Owain Kenway%0A'''%0A%0A# Write PGM images.%0A# d - the 2d list to write.%0A# white - the value of white (max value).%0A# filename - the file to write to.%0Adef writepgm(d, white, filename):%0A    x = len(d)%0A    y = len(d%5B0%5D)%0A%0A# Open our file.%0A    f = open(filename, 'w')%0A%0A# Write header.%0A    f.write('P2%5Cn')%0A    f.write('# Written by pnmmodules (https://github.com/owainkenwayucl/pnmmodules).%5Cn')%0A    f.write(str(x) + ' ' + str(y) + '%5Cn')%0A    f.write(str(white) + '%5Cn')%0A%0A# Write out 2d list.%0A    for j in range(y):%0A        for i in range(x):%0A            f.write(str(d%5Bi%5D%5Bj%5D) + '%5Cn')%0A%0A%0A# Tidy up.%0A    f.close()%0A%0A# Write PBM images.%0A# d - the 2d list to write.%0A# threshold - the value of at which 0 becomes 1.%0A# filename - the file to write to.%0Adef writepbm(d, threshold, filename):%0A    x = len(d)%0A    y = len(d%5B0%5D)%0A%0A# Open our file.%0A    f = open(filename, 'w')%0A%0A# Write header.%0A    f.write('P1%5Cn')%0A    f.write('# Written by pnmmodules (https://github.com/owainkenwayucl/pnmmodules).%5Cn')%0A    f.write(str(x) + ' ' + str(y) + '%5Cn')%0A%0A# Write out 2d list.%0A    for j in range(y):%0A        for i in range(x):%0A            if d%5Bi%5D%5Bj%5D %3E= threshold:%0A                f.write('1%5Cn')%0A            else:%0A                f.write('0%5Cn')%0A%0A# Tidy up.%0A    f.close()

Add imageio code from pnmmodules.