Ive made a simple image viewer using the python examples and it all works fine. However, I would also like to save the image file used to a text file.
Code is:
#!/usr/bin/env python
import time
import sys
from rgbmatrix import RGBMatrix, RGBMatrixOptions
from PIL import Image
def write_to_file(filename, towrite):
f = open(filename, "w")
print(towrite)
f.write(towrite)
f.close()
if len(sys.argv) < 2:
sys.exit("Require an image argument")
else:
image_file = sys.argv[1]
image = Image.open(image_file)
# Configuration for the matrix
options = RGBMatrixOptions()
options.rows = 32
options.chain_length = 4
options.parallel = 1
options.hardware_mapping = 'adafruit-hat' # If you have an Adafruit HAT: 'adafruit-hat'
matrix = RGBMatrix(options = options)
image.thumbnail((matrix.width, matrix.height), Image.ANTIALIAS)
matrix.SetImage(image.convert('RGB'))
write_to_file("marquee.txt", image_file)
try:
print("Press CTRL-C to stop.")
while True:
time.sleep(100)
except KeyboardInterrupt:
sys.exit(0)
However, when I run this, I get a permission error:
File “file_test3.py”, line 34, in
write_to_file(“marquee.txt”, image_file)
File “file_test3.py”, line 9, in write_to_file
f = open(filename, “w”)
PermissionError: [Errno 13] Permission denied: ‘marquee.txt’
I tried various combinations of the code and there seems to be an interaction when definining the ‘matrix’. If I comment out the lines:
matrix = RGBMatrix(options = options)
image.thumbnail((matrix.width, matrix.height), Image.ANTIALIAS)
matrix.SetImage(image.convert('RGB'))
Then I no longer get the permissions error. Any ideas?