fork download
  1. from PIL import Image
  2.  
  3. input_file = "input.png"
  4. output_file = "output.txt"
  5.  
  6. img = Image.open(input_file).convert("RGB")
  7.  
  8. width, height = img.size
  9. pixels = img.load()
  10.  
  11. with open(output_file, "w", encoding="utf-8") as f:
  12. for y in range(height):
  13. row = []
  14.  
  15. for x in range(width):
  16. r, g, b = pixels[x, y]
  17. hexcode = f"#{r:02X}{g:02X}{b:02X}"
  18. row.append(hexcode)
  19.  
  20. f.write("\t".join(row) + "\n")
  21.  
  22. print("done")
Runtime error #stdin #stdout #stderr 1.1s 38072KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 6, in <module>
  File "/usr/local/lib/python3.12/dist-packages/PIL/Image.py", line 3131, in open
    fp = builtins.open(filename, "rb")
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'input.png'