Skip to content

Commit

Permalink
stitch_to_animation: gif kwargs working again (#1149)
Browse files Browse the repository at this point in the history
* working with v3 api

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update setup.py

* Update CHANGELOG.md

* add verbose back in

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update _helpers.py

use writer

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update setup.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: kameyer226 <61993880+kameyer226@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 30, 2024
1 parent c6f4378 commit f772f2c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).

### Fixed
- `interact2D`: fixed bug where use_imshow broke the sliders
- `artists.stitch_to_animation`: use imageio v3 api and declare pillow plugin
- `data.join` ensures valid `method` is selected

### Changed
Expand Down
23 changes: 11 additions & 12 deletions WrightTools/artists/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import matplotlib.patheffects as PathEffects
from mpl_toolkits.axes_grid1 import make_axes_locatable

import imageio
import imageio.v3 as iio
import warnings

from .. import exceptions as wt_exceptions
Expand Down Expand Up @@ -1081,14 +1081,14 @@ def subplots_adjust(fig=None, inches=1):
fig.subplots_adjust(top=top, right=right, bottom=bottom, left=left)


def stitch_to_animation(images, outpath=None, *, duration=0.5, palettesize=256, verbose=True):
def stitch_to_animation(paths, outpath=None, *, duration=0.5, palettesize=256, verbose=True):
"""Stitch a series of images into an animation.
Currently supports animated gifs, other formats coming as needed.
Parameters
----------
images : list of strings
paths : list of strings
Filepaths to the images to stitch together, in order of apperence.
outpath : string (optional)
Path of output, including extension. If None, bases output path on path
Expand All @@ -1097,22 +1097,21 @@ def stitch_to_animation(images, outpath=None, *, duration=0.5, palettesize=256,
Duration of (each) frame in seconds. Default is 0.5.
palettesize : int (optional)
The number of colors in the resulting animation. Input is rounded to
the nearest power of 2. Default is 1024.
the nearest power of 2. Default is 256.
verbose : bool (optional)
Toggle talkback. Default is True.
"""
# parse filename
if outpath is None:
outpath = os.path.splitext(images[0])[0] + ".gif"
outpath = os.path.splitext(paths[0])[0] + ".gif"
# write
t = wt_kit.Timer(verbose=False)
with t, imageio.get_writer(
outpath, mode="I", duration=duration, palettesize=palettesize
) as writer:
for p in images:
image = imageio.imread(p)
writer.append_data(image)
# finish
with t, iio.imopen(outpath, "w") as gif:
for p in paths:
frame = iio.imread(p)
gif.write(
frame, plugin="pillow", duration=duration * 1e3, loop=0, palettesize=palettesize
)
if verbose:
interval = np.round(t.interval, 2)
print("gif generated in {0} seconds - saved at {1}".format(interval, outpath))
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def read(fname):
python_requires=">=3.7",
install_requires=[
"h5py",
"imageio",
"imageio>=2.28.0",
"matplotlib>=3.4.0",
"numexpr",
"numpy>=1.15.0",
Expand Down

0 comments on commit f772f2c

Please sign in to comment.