add cr2 image support

This commit is contained in:
j 2025-07-06 20:44:31 +01:00
commit 68ad3562c4
4 changed files with 8 additions and 4 deletions

View file

@ -8,7 +8,8 @@ from django.conf import settings
logger = logging.getLogger('pandora.' + __name__)
IMAGE_EXTENSIONS = ('png', 'jpg', 'webp', 'heic', 'heif')
IMAGE_EXTENSIONS = ('png', 'jpg')
CONVERT_EXTENSIONS = ('webp', 'heic', 'heif', 'cr2')
def extract_text(pdf, page=None):
if page is not None:
@ -56,6 +57,8 @@ class FulltextMixin:
return extract_text(self.file.path)
elif self.extension in IMAGE_EXTENSIONS:
return ocr_image(self.file.path)
elif self.extension in CONVERT_EXTENSIONS:
return ocr_image(self.file.path)
elif self.extension == 'html':
return self.data.get('text', '')
return ''

View file

@ -564,7 +564,7 @@ class Document(models.Model, FulltextMixin):
path = os.path.join(folder, '%dp%d,%s.jpg' % (size, page, ','.join(map(str, crop))))
if not os.path.exists(path):
resize_image(src, path, size=size)
elif self.extension in ('jpg', 'png', 'gif', 'webp', 'heic', 'heif'):
elif self.extension in ('jpg', 'png', 'gif', 'webp', 'heic', 'heif', 'cr2'):
if os.path.exists(src):
if size and page:
crop = list(map(int, page.split(',')))

View file

@ -383,7 +383,7 @@ def file(request, id, name=None):
mime_type = mimetypes.guess_type(document.file.path)[0]
mime_type = 'image/%s' % document.extension
if accept and 'image/' in accept and document.extension in (
'webp', 'heif', 'heic', 'avif', 'tiff'
'webp', 'heif', 'heic', 'avif', 'tiff',
) and mime_type not in accept:
image_size = max(document.width, document.height)
return HttpFileResponse(document.thumbnail(image_size, accept=accept))

View file

@ -422,6 +422,7 @@ pandora.createLinks = function($element) {
pandora.imageExtensions = [
'avif',
'cr2',
'gif',
'heic',
'heif',
@ -429,7 +430,7 @@ pandora.imageExtensions = [
'jpg',
'png',
'tiff',
'webp'
'webp',
];
pandora.documentExtensions = [