1

I'm using imageio to generate a GIF from a set of PNGs that I've created using PIL. Here's my code (found here):

    import imageio

    path = "./img/"
    os.chdir(path)
    filenames = sorted((fn for fn in os.listdir('.') if fn.endswith('.png')))

    with imageio.get_writer('./img/movie.gif', mode='I') as writer:
        for filename in filenames:
            image = imageio.mimread(filename)
            writer.append_data(image)

However, I keep getting the following error:

    Traceback (most recent call last):
      File "gifcreate.py", line 7, in <module>
        image = imageio.mimread(filename)
      File "/Users/felipe_campos/Documents/DECO/venv/lib/python2.7/site-packages/imageio/core/functions.py", line 261, in mimread
        reader = read(uri, format, 'I', **kwargs)
      File "/Users/felipe_campos/Documents/DECO/venv/lib/python2.7/site-packages/imageio/core/functions.py", line 108, in get_reader
'in mode %r' % mode)
    ValueError: Could not find a format to read the specified file in mode 'I'

Does anybody have any ideas as to what I can do? I tried running it outside the virtual environment but it keeps telling me ImportError: No module named imageio (same with scipy and a few other modules), so I'm at a loss for what to do.

EDIT:

Figured it out, just use imread(filename) instead of mimread(filename) and it worked fine.

Community
  • 1
  • 1

1 Answers1

1

This looks like a defect / bug.

for filename in filenames:

in this case filenames is a str, which is an iterable, and python will happily iterate over it.

Why not try doing filenames = ['./img/', ] and see what happens.

(A really quick glance at the docs for imageio and I'm not sure the calling signature expects a directory - I think it's looking for the actual filename)

uri : {str, bytes, file}

The resource to load the images from. This can be a normal filename, a file in a zipfile, an http/ftp address, a file object, or the raw bytes.

If what you want to do is iteratate over all files in a directory maybe look at os in python for that.

James R
  • 4,571
  • 3
  • 30
  • 45
  • Yeah so I kinda just realized how stupid it was to try to iterate over a string expecting the compiler to know that I meant for it to be a directory so changed my code (reflected above) but am still getting the same error. – Felipe Mulinari Rocha Campos Mar 16 '17 at 00:31