Coder Social home page Coder Social logo

Comments (2)

Dotrar avatar Dotrar commented on May 21, 2024

forgot to mention, adding in

def readline(self):
    return self.read(100)

fixes the crash and allows imageio to open my image, by the way.

from imageio.

FirefoxMetzger avatar FirefoxMetzger commented on May 21, 2024

I'm trying to open a url of a larger JPG from an s3 storage. It's unable to ascertain the file-type

How come?

Assuming you pass a URL and the file either ends with a JPEG suffix (e.g. .jpg) then ImageIO will try plugins known to read JPEG first and only fall back to trying everything if the "known-to-read-jpeg" plugins fail. If the URL doesn't end with a JPEG suffix, but you know it to be JPEG, you can also pass extension=".jpg" as an additional kwarg to imopen, imread, etc. to set/overwrite the suffix of the resource itself.

it goes for the "try every plugin" approach:

If you already know you want to read using pillow you can also pass plugin="pillow" as an additional kwarg, in which case plugin selection is skipped in favour of using the plugin you specified.

But SeekableFileObject does not have readline, causing an error.

Since SeekableFileObject is a binary file and lacks the notion of a "line of text" or an "EOL character (\n)". As such the function reads a single line from the file doesn't make much sense in this context and we didn't implement readline.

Using Pillow ImImagePlugin to read a file, we attempt a readline as seen here @ Pillow

The plugin you are quoting here is the plugin for reading IFUNC Image Memory not JPEG. I have actually never encountered this format and Google and the pillow repo are suspiciously silent about it. I suspect that this is a legacy format that is no longer in active use and that should probably not be used further.

def readline(self):
   return self.read(100)

The problem with setting readline to read the first 100 bytes is that this is an arbitrary cutoff. This may or may not mean something for the underlying data of the stream and will most likely leave the head at an awkward and unexpected location.

I am still not convinced we want to add readline, but were we to do so we probably want to read the entire file. In my mind "read until you encounter the end of the current line" plus "there is no end of line for binary files" results in "read until the end of the file".


Regarding the actual problem of ImageIO being unable to read a large JPEG from S3, are you able to share a code snippet that reproduces the failure?

Walking over all plugins and trying them out is expensive and more of a last resort than something we want to do on a regular basis. If we can avoid this by doing something smart during plugin selection I'd be quite interested in this option.

from imageio.

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.