niol / lazygal

Static web gallery generator
https://sml.zincube.net/~niol/repositories.git/lazygal/about/
GNU General Public License v2.0
6 stars 3 forks source link

Lazygal fails on background color with cannot write mode RGBA with JPEG #12

Closed ericzolf closed 3 years ago

ericzolf commented 3 years ago

I'm new to lazygal so I might have misunderstood something, but if I generate exactly from the same source directory, it works, but not with --webalbum-pic-bg:

$ lazygal -o TARGET_DIR --webalbum-pic-bg=#000 --check-all-dirs --webalbum-pic-type messy SOURCE_DIR
[Entering %ALBUMROOT%/]                
  DUMPJSON index.json                  
  MKDIR %WEBALBUMROOT%/                
  BREAKING web gallery into multiple pages
  RESIZE 5269_IMG_small.jpg
[...]
  XHTML 5223_IMG_medium.html              
  XHTML index_medium.html                 
  DIRPIC index.jpg                        
Progress: dir 0/1 (0%), media 70/70 (100%)Traceback (most recent call last):
  File "/usr/lib64/python3.9/site-packages/PIL/JpegImagePlugin.py", line 610, in _save
    rawmode = RAWMODE[im.mode]
KeyError: 'RGBA'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/bin/lazygal", line 294, in <module>
    album.generate(progress=progress)
  File "/usr/lib/python3.9/site-packages/lazygal/generators.py", line 943, in generate
    destgal.make()
  File "/usr/lib/python3.9/site-packages/lazygal/generators.py", line 667, in make
    super().make(force)
  File "/usr/lib/python3.9/site-packages/lazygal/make.py", line 123, in make
    d.make()  # dependency building not forced
  File "/usr/lib/python3.9/site-packages/lazygal/make.py", line 124, in make
    self.call_build()
  File "/usr/lib/python3.9/site-packages/lazygal/make.py", line 133, in call_build
    self.build()
  File "/usr/lib/python3.9/site-packages/lazygal/genmedia.py", line 290, in build
    self.dirpic.write(self.path)
  File "/usr/lib/python3.9/site-packages/lazygal/eyecandy.py", line 142, in write
    self.picture_mess.save(output_file)
  File "/usr/lib64/python3.9/site-packages/PIL/Image.py", line 2164, in save
    save_handler(self, fp, filename)
  File "/usr/lib64/python3.9/site-packages/PIL/JpegImagePlugin.py", line 612, in _save
    raise OSError(f"cannot write mode {im.mode} as JPEG") from e
OSError: cannot write mode RGBA as JPEG

I tried different colors: black, Black, #000, DarkBlue, all give the same result (I removed the target directory before each try)

lazygal-0.10.2-1.fc34.noarch (Fedora 34), Python 3.9 and the following dependencies:

$ rpm -qa | grep -i -e pillow -e genshi -e gexiv2 -e ffmpeg
python3-genshi-0.7.5-3.fc34.noarch
libgexiv2-0.12.2-2.fc34.x86_64
python3-gexiv2-0.12.2-2.fc34.x86_64
compat-ffmpeg28-2.8.17-4.fc34.x86_64
python3-pillow-8.1.2-3.fc34.x86_64
ffmpeg-libs-4.4-4.fc34.x86_64
ffmpeg-4.4-4.fc34.x86_64
niol commented 3 years ago

Do you happen to have a png in your source directory?

ericzolf commented 3 years ago

No, only JPG directly from a Canon camera. After your remark, I thought it might be due to a stray PNG in the current directory but it isn't either the case. I tried different source directories, and I always get the same issue. At the end I ended in an empty directory calling lazygal --webalbum-pic-bg=black /some/directory/with/two/random/jpegs and still got the issue.

Trying the same thing with a directory of PNG files, I get mostly the same error, sometimes with mode P instead of mode RGBA. I guess it depends on the type of PNG, I have 8-bit Gray 256c, 8-bit sRGB and 8-bit sRGB 2c, and only the last one gives me the P-mode, the others have RGBA.

niol commented 3 years ago

I won't have access to my laptop for about one week and will get back to you then if I cannot reproduce.

niol commented 3 years ago

Should be fixed, thanks!