Giter Site home page Giter Site logo

Comments (2)

jrief avatar jrief commented on June 21, 2024

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.

from easy-thumbnails.

DmytroLitvinov avatar DmytroLitvinov commented on June 21, 2024

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

from easy-thumbnails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.