Skip to content

Commit

Permalink
v1.0.4
Browse files Browse the repository at this point in the history
- Support using APNGAsmBinder with statement (context manager)
- Update examples
- FIx permissions of example scripts
  • Loading branch information
laggykiller committed Sep 5, 2023
1 parent 73cbb28 commit 8fe915e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ else()
endif()
endif()

project(apngasm-python VERSION 1.0.3)
project(apngasm-python VERSION 1.0.4)
set(PY_VERSION_SUFFIX "")
set(PY_FULL_VERSION ${PROJECT_VERSION}${PY_VERSION_SUFFIX})

Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,21 @@ for file_name in sorted(os.listdir('frames')):
# This sets the APNG animation to loop for 3 times before stopping
apngasm.set_loops(3)
apng.assemble('result-from-file.apng')
apngasm.reset()

# From Pillow
apngasm.reset()
for file_name in sorted(os.listdir('frames')):
image = Image.open(os.path.join('frames', file_name)).convert('RGBA')
frame = apngasm.add_frame_from_pillow(image, delay_num=50, delay_den=1000)
apngasm.assemble('result-from-pillow.apng')
apngasm.reset()

# Disassemble and get pillow image of one frame
apngasm.reset()
frames = apngasm.disassemble_as_pillow('input/ball.apng')
frame = frames[0]
frame.save('output/ball0.png')
# You can use with statement to avoid calling reset()
with APNGAsmBinder() as apng:
frames = apng.disassemble_as_pillow('input/ball.apng')
frame = frames[0]
frame.save('output/ball0.png')

# Disassemble all APNG into PNGs
apngasm.save_pngs('output')
Expand Down
13 changes: 7 additions & 6 deletions example/example_binder.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,17 @@

success = apngasm.assemble('output/elephant-spinning-pillow.apng')
print(f'{success = }')
apngasm.reset()

# Assemble palette and grey PNGs
apngasm.reset()
apngasm.add_frame_from_file('input/palette.png')
apngasm.add_frame_from_file('input/grey.png')
success = apngasm.assemble('output/birds.apng')
print(f'{success = }')
# You can use with statement to avoid calling reset()
with APNGAsmBinder() as apng:
apng.add_frame_from_file('input/palette.png')
apng.add_frame_from_file('input/grey.png')
success = apng.assemble('output/birds.apng')
print(f'{success = }')

# Assemble palette and grey PNGs, but with Pillow
apngasm.reset()
image0 = Image.open('input/grey.png')
frame0 = apngasm.add_frame_from_pillow(image0)
image1 = Image.open('input/palette.png')
Expand Down
Empty file modified example/example_direct.py
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion src-python/apngasm_python/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'''apngasm-python'''
__version__ = '1.0.3'
__version__ = '1.0.4'

from .apngasm import APNGAsmBinder
8 changes: 5 additions & 3 deletions src-python/apngasm_python/apngasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class APNGAsmBinder:

def __init__(self):
self.apngasm = APNGAsm()

def __del__(self):

def __enter__(self):
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.apngasm.reset()
del self.apngasm

def frame_pixels_as_pillow(self, frame, new_value=None):
'''
Expand Down

0 comments on commit 8fe915e

Please sign in to comment.