Skip to content

Commit

Permalink
include missed files
Browse files Browse the repository at this point in the history
  • Loading branch information
hyzhak committed May 27, 2017
1 parent 9966a79 commit dbb730b
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ instance/
docs/_build/

# PyBuilder
target/
./target/

# IPython Notebook
.ipynb_checkpoints
Expand Down
3 changes: 3 additions & 0 deletions nasabot/geo/animation/target/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from nasabot.geo.animation.target.gif import Gif

__all__ = [Gif]
35 changes: 35 additions & 0 deletions nasabot/geo/animation/target/gif.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import logging
import os
from nasabot.geo.animation.target import \
imageio_animation, wand_animation
from slugify import slugify

logger = logging.getLogger(__name__)


def uri_2_filename(uri):
"""
convert uri to related filename
:param uri:
:return:
"""
*first, ext = uri.split('.')
return slugify('.'.join(first)) + '.' + ext


class Gif:
def __init__(self, target_filename=''):
self.target_filename = target_filename
self.root_path = os.path.dirname(target_filename)

# TODO: should make it selectable
self.animation_provider = imageio_animation
# self.animation_provider = wand_animation

def get_filename_by_url(self, url):
return os.path.join(self.root_path, uri_2_filename(url))

async def save(self, files):
await self.animation_provider.animate(
os.path.join(self.target_filename), files)
logger.info('# gif file is saved to {}'.format(self.target_filename))
19 changes: 19 additions & 0 deletions nasabot/geo/animation/target/imageio_animation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import logging
import imageio

logger = logging.getLogger(__name__)


async def animate(export_filename, file_sequence):
"""
:param file_sequence:
:return:
"""
logger.debug('# animate sequence of files')
logger.debug(file_sequence)

frames = [imageio.imread(file_name) for file_name in file_sequence]
imageio.mimsave(export_filename, frames, 'GIF',
# fps=30,
)
22 changes: 22 additions & 0 deletions nasabot/geo/animation/target/wand_animation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import logging
from wand.image import Image

logger = logging.getLogger(__name__)


async def animate(export_filename, file_sequence):
"""
20-40% slower than imageio :(
:param file_sequence:
:return:
"""
logger.debug('animate sequence of files')
logger.debug(file_sequence)

with Image() as gif:
for file_name in file_sequence:
with Image(filename=file_name) as frame:
gif.sequence.append(frame)
gif.type = 'optimize'
gif.save(filename=export_filename)

0 comments on commit dbb730b

Please sign in to comment.