hi im doing an automated youtube channel i dont know much about programming can someone help me .. im getting this error if OSError: cannot write mode P as JPEG
here is the code for it i think as i said im dont know much i was copying what the guy was doing
I added the full error at last id appreciate a help
# stuff to save JPEG files
RAWMODE = {
"1": "L",
"L": "L",
"RGB": "RGB",
"RGBX": "RGB",
"CMYK": "CMYK;I", # assume adobe conventions
"YCbCr": "YCbCr",
}
# fmt: off
zigzag_index = (
0, 1, 5, 6, 14, 15, 27, 28,
2, 4, 7, 13, 16, 26, 29, 42,
3, 8, 12, 17, 25, 30, 41, 43,
9, 11, 18, 24, 31, 40, 44, 53,
10, 19, 23, 32, 39, 45, 52, 54,
20, 22, 33, 38, 46, 51, 55, 60,
21, 34, 37, 47, 50, 56, 59, 61,
35, 36, 48, 49, 57, 58, 62, 63,
)
samplings = {
(1, 1, 1, 1, 1, 1): 0,
(2, 1, 1, 1, 1, 1): 1,
(2, 2, 1, 1, 1, 1): 2,
}
# fmt: on
def convert_dict_qtables(qtables):
warnings.warn(
"convert_dict_qtables is deprecated and will be removed in Pillow 10"
"(2023-01-02). Conversion is no longer needed.",
DeprecationWarning,
)
return qtables
def get_sampling(im):
# There's no subsampling when images have only 1 layer
# (grayscale images) or when they are CMYK (4 layers),
# so set subsampling to the default value.
#
# NOTE: currently Pillow can't encode JPEG to YCCK format.
# If YCCK support is added in the future, subsampling code will have
# to be updated (here and in JpegEncode.c) to deal with 4 layers.
if not hasattr(im, "layers") or im.layers in (1, 4):
return -1
sampling = im.layer[0][1:3] + im.layer[1][1:3] + im.layer[2][1:3]
return samplings.get(sampling, -1)
def _save(im, fp, filename):
try:
rawmode = RAWMODE[im.mode]
except KeyError as e:
raise OSError(f"cannot write mode {im.mode} as JPEG") from e
FULL ERROR
Traceback (most recent call last):
File "C:\Users\USER\Desktop\AutoTube\myvenv\lib\site-packages\PIL\JpegImagePlugin.py", line 630, in _save
rawmode = RAWMODE[im.mode]
KeyError: 'P'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "c:\Users\USER\Desktop\AutoTube\main.py", line 31, in <module>
redditbot.save_image(post)
File "c:\Users\USER\Desktop\AutoTube\utils\RedditBot.py", line 73, in save_image
scale_gif(image_path, scale)
File "c:\Users\USER\Desktop\AutoTube\utils\Scalegif.py", line 19, in scale_gif
gif.save(path)
File "C:\Users\USER\Desktop\AutoTube\myvenv\lib\site-packages\PIL\Image.py", line 2240, in save
save_handler(self, fp, filename)
File "C:\Users\USER\Desktop\AutoTube\myvenv\lib\site-packages\PIL\JpegImagePlugin.py", line 632, in _save
raise OSError(f"cannot write mode {im.mode} as JPEG") from e
OSError: cannot write mode P as JPEG