Giter Site home page Giter Site logo

Comments (5)

michelts avatar michelts commented on July 19, 2024

Hi again,

Digging into the problem, I worry that we cannot make a storage object have a tell and a seek methods. I found a similar problem related on the "Dive into python":

http://diveintopython.org/http_web_services/gzip_compression.html#d0e29389

In that doc, the recomendation is to use StringIO to wrap the file content.

I done it on my local version of easy-thumbnails, in the "files.py" module:

    data = self.read()
    datastream = StringIO.StringIO(data)
    self._cached_image = Image.open(datastream)

I will check if there is anything I missing like any performance penalty and see how to force the image type (because of the StringIO's lack of filename).

I'm not familiar with GitHub yet, if you agree with this fix, I can read about creating a fork or a patch.

Thanks!

from easy-thumbnails.

SmileyChris avatar SmileyChris commented on July 19, 2024

Hi Michel - just to let you know I am paying attention to these issues. I'm going to do some more testing of the different storage backends soon, in anticipation for releasing a non-alpha finally :)

I'm guessing that you haven't specifically checked for performance penalty yet?

from easy-thumbnails.

michelts avatar michelts commented on July 19, 2024

Hi Chris,

I did some tests today. I run it on my local environment. It consisted on create a huge image gallery with high resolution pictures. While the gallery is being thumbnailed, I follow the RAM use using top command. The system act the same with my patch and without it. It seems ok because the original image saved on the memory (to the StringIO instance) is not kept.

I do not tested in a online environment but I don't think there will be any penalty. The greater time lost is during the images transmission through server/cloudfiles and cloudfiles/server.

I will do more tests. Anyway, I updated the code according to the updates on the easy_thumbnails. This is a source_generator method with the update:

def pil_image(source, **options):
    """
    Try to open the source file by passing his content to PIL, ignoring any errors.

    """
    # if the source is an incomplete file like object, PIL may have problems
    # with it (it demands tell and seek methods that are not present on all
    # storage objects). This way, reather than use the source file, we use his
    # content on a StringIO wrapper.
    data = source.read()
    data_wrapper = StringIO.StringIO(data)
    try:
        image = Image.open(data_wrapper)
    except:
        return
    # Image.open() is a lazy operation, so force the load so the source file
    # can be closed again if appropriate.
    image.load()
    return image

Thanks!

from easy-thumbnails.

SmileyChris avatar SmileyChris commented on July 19, 2024

Thanks for testing that! It seems a straight forwards enough change then.

I'm not sure image.load will be needed anymore, since the source can be closed without that now.

from easy-thumbnails.

SmileyChris avatar SmileyChris commented on July 19, 2024

Fixed in f122c2e

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.