diff --git a/icons/mkicon.py b/icons/mkicon.py index db535b93..d1bca2fa 100755 --- a/icons/mkicon.py +++ b/icons/mkicon.py @@ -901,9 +901,9 @@ def testrun(func, fname): for canvas in canvases: minx, miny, maxx, maxy = bbox(canvas) block.extend(render(canvas, minx-2, miny-2, minx-2+wid, maxy+2)) - with open(fname, "w") as f: - f.write(("P7\nWIDTH %d\nHEIGHT %d\nDEPTH 3\nMAXVAL 255\n" + - "TUPLTYPE RGB\nENDHDR\n") % (wid, ht)) + with open(fname, "wb") as f: + f.write((("P7\nWIDTH %d\nHEIGHT %d\nDEPTH 3\nMAXVAL 255\n" + + "TUPLTYPE RGB\nENDHDR\n") % (wid, ht)).encode('ASCII')) assert len(block) == ht for line in block: assert len(line) == wid @@ -912,7 +912,7 @@ def testrun(func, fname): r = int(round((r * a + 255 * (255-a)) / 255.0)) g = int(round((g * a + 128 * (255-a)) / 255.0)) b = int(round((b * a + 0 * (255-a)) / 255.0)) - f.write("%c%c%c" % (r,g,b)) + f.write(bytes(bytearray([r, g, b]))) def drawicon(func, width, fname, orangebackground = 0): canvas = func(width / 32.0) @@ -921,9 +921,10 @@ def drawicon(func, width, fname, orangebackground = 0): assert minx >= 0 and miny >= 0 and maxx <= width and maxy <= width block = render(canvas, 0, 0, width, width) - with open(fname, "w") as f: - f.write(("P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\n" + - "TUPLTYPE RGB_ALPHA\nENDHDR\n") % (width, width)) + with open(fname, "wb") as f: + f.write((("P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\n" + + "TUPLTYPE RGB_ALPHA\nENDHDR\n") % + (width, width)).encode('ASCII')) assert len(block) == width for line in block: assert len(line) == width @@ -934,7 +935,7 @@ def drawicon(func, width, fname, orangebackground = 0): g = int(round((g * a + 128 * (255-a)) / 255.0)) b = int(round((b * a + 0 * (255-a)) / 255.0)) a = 255 - f.write("%c%c%c%c" % (r,g,b,a)) + f.write(bytes(bytearray([r, g, b, a]))) args = sys.argv[1:]