mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-09 09:58:20 -05:00
Let convert handle the removal of the alpha channel
This commit is contained in:
parent
24ce1830eb
commit
59e0c1fe4e
@ -1,6 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
@ -79,6 +80,17 @@ class RasterisedDocumentParser(DocumentParser):
|
|||||||
with Image.open(image) as im:
|
with Image.open(image) as im:
|
||||||
return im.mode in ("RGBA", "LA")
|
return im.mode in ("RGBA", "LA")
|
||||||
|
|
||||||
|
def remove_alpha(self, image_path: str):
|
||||||
|
subprocess.run(
|
||||||
|
[
|
||||||
|
settings.CONVERT_BINARY,
|
||||||
|
"-alpha",
|
||||||
|
"off",
|
||||||
|
image_path,
|
||||||
|
image_path,
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def get_dpi(self, image):
|
def get_dpi(self, image):
|
||||||
try:
|
try:
|
||||||
with Image.open(image) as im:
|
with Image.open(image) as im:
|
||||||
@ -230,11 +242,7 @@ class RasterisedDocumentParser(DocumentParser):
|
|||||||
f"Removing alpha layer from {input_file} "
|
f"Removing alpha layer from {input_file} "
|
||||||
"for compatibility with img2pdf",
|
"for compatibility with img2pdf",
|
||||||
)
|
)
|
||||||
with Image.open(input_file) as im:
|
self.remove_alpha(input_file)
|
||||||
background = Image.new("RGBA", im.size, (255, 255, 255))
|
|
||||||
background.alpha_composite(im)
|
|
||||||
background = background.convert("RGB")
|
|
||||||
background.save(input_file, format=im.format)
|
|
||||||
|
|
||||||
if dpi:
|
if dpi:
|
||||||
self.log("debug", f"Detected DPI for image {input_file}: {dpi}")
|
self.log("debug", f"Detected DPI for image {input_file}: {dpi}")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user