Open DmytroLitvinov opened 11 months ago
Since I have no access to S3, I can't test this. Would you be so kind and share the patch of your colleague as a PR.
Sure,
Here is a patch we applied and it works for us:
def database_get_image_dimensions(file, close=False, dimensions=None): # noqa: VNE002
"""
Change svg file dimensions, because - https://github.com/SmileyChris/easy-thumbnails/issues/619
"""
storage_hash = utils.get_storage_hash(file.storage)
dimensions = None
dimensions_cache = None
try:
thumbnail = models.Thumbnail.objects.select_related('dimensions').get(storage_hash=storage_hash, name=file.name)
except models.Thumbnail.DoesNotExist:
thumbnail = None
else:
try:
dimensions_cache = thumbnail.dimensions
except models.ThumbnailDimensions.DoesNotExist:
dimensions_cache = None
if dimensions_cache:
return dimensions_cache.width, dimensions_cache.height
if os.path.splitext(file.file.name)[1] == '.svg':
from easy_thumbnails.VIL.Image import load
dimensions = load(file.file).size
else:
dimensions = get_image_dimensions(file, close=close)
if settings.THUMBNAIL_CACHE_DIMENSIONS and thumbnail:
models.ThumbnailDimensions.objects.get_or_create(
thumbnail=thumbnail, defaults={'width': dimensions[0], 'height': dimensions[1]}
)
return dimensions
easy_thumbnails_files.database_get_image_dimensions = database_get_image_dimensions
We are using AWS S3 as a remote storage. And we found an issue when we use SVG file with
django-filer
library and then we tried to use thumbnail template tags which is used next code:The issue itself with
thumb.width
which is under the hood is failed with next traceback:The issue is in 121th line. After checking with blame functionally, I see
file.path
was adapted because of that possible case - more information in that commit https://github.com/SmileyChris/easy-thumbnails/commit/8a06fc7db58a4b796673c20876b124be554aaabc. We see thatfile.path
was omitted withfile.file.name
.Not sure if it will resolve, but in that line of code - https://github.com/SmileyChris/easy-thumbnails/blob/77265b715a1f623b3c42abc8d044535d880971bd/easy_thumbnails/files.py#L121 we should pass
file.file
instead offile.path
.Currently, my colleague is working on monkey-patch to verify it so I will update after my ticket. UPD: colleague confirmed that monkey-patch works
@jrief , I would appreciate your feedback on the issue since you are who was in developing it. Thank you🙏