mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-20 05:26:53 +01:00
Feature: Allow user to control PIL image pixel limit (#5997)
This commit is contained in:
parent
35574f3b86
commit
b9636a3def
7 changed files with 47 additions and 1 deletions
|
|
@ -1,8 +1,12 @@
|
|||
import shutil
|
||||
from os import utime
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from typing import Union
|
||||
|
||||
from django.conf import settings
|
||||
from PIL import Image
|
||||
|
||||
|
||||
def _coerce_to_path(
|
||||
source: Union[Path, str],
|
||||
|
|
@ -40,3 +44,15 @@ def copy_file_with_basic_stats(
|
|||
|
||||
shutil.copy(source, dest)
|
||||
copy_basic_file_stats(source, dest)
|
||||
|
||||
|
||||
def maybe_override_pixel_limit() -> None:
|
||||
"""
|
||||
Maybe overrides the PIL limit on pixel count, if configured to allow it
|
||||
"""
|
||||
limit: Optional[Union[float, int]] = settings.MAX_IMAGE_PIXELS
|
||||
if limit is not None and limit >= 0:
|
||||
pixel_count = limit
|
||||
if pixel_count == 0:
|
||||
pixel_count = None
|
||||
Image.MAX_IMAGE_PIXELS = pixel_count
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue