Skip to content

webp writer writes 0 bytes to BytesIO  #498

Closed

Description

@leoshine

Toy code to reproduce the issue (tested on both linux and osx):

# webp writer writes 0 bytes to BytesIO 
with io.BytesIO() as bio:
    im_rgb = imageio.imread('src_input.jpg')  
    with imageio.get_writer(bio, format='webp', mode='i') as writer: # doesn't work for webp.
        writer.append_data(im_rgb)
    data = bio.getvalue()
    print(len(data))  # always return 0 here for 'webp' (but it is fine for jpg, png, ect)

Activity

  1. almarklein commented on Jan 13, 2020

    @almarklein
    Member

    Could you try format='targa-FI'? That would also use the default FreeImage plugin. Maybe it helps to determine where it goes wrong. I don't seem to be able to write webp on Windows.

  2. FirefoxMetzger commented on Feb 11, 2022

    @FirefoxMetzger
    Contributor

    Pillow is perfectly happy to read and write WEBP, so we are too:

    import imageio.v3 as iio
    
    img = iio.imread("imageio:newtonscradle.gif", index=None)
    iio.imwrite("single_frame.webp", img[0])
    img2 = iio.imread("single_frame.webp")

    You can also write multiple frames (like a GIF), but then you have to explicitly supply a duration (pillow doesn't offer a default, so we don't set one either):

    import imageio.v3 as iio
    
    img = iio.imread("imageio:newtonscradle.gif", index=None)
    iio.imwrite("animation.webp", img, duration=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions