From 985bbd42b641eda3c6f939a9a4c3712a38a06094 Mon Sep 17 00:00:00 2001 From: Mauricio Date: Sun, 2 Aug 2020 21:08:46 -0400 Subject: [PATCH] remove 'image_crap.py' and add 'images.py' --- image_crap.py | 9 --------- images.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) delete mode 100644 image_crap.py create mode 100644 images.py diff --git a/image_crap.py b/image_crap.py deleted file mode 100644 index 3a0563a..0000000 --- a/image_crap.py +++ /dev/null @@ -1,9 +0,0 @@ -from PIL import Image -from PyQt4 import QtGui -import io - -def load_apng(file): - pass - -def load_webp(file): - pass \ No newline at end of file diff --git a/images.py b/images.py new file mode 100644 index 0000000..7b0ae8d --- /dev/null +++ b/images.py @@ -0,0 +1,30 @@ +from PIL import Image +from PyQt4 import QtGui +from apng import APNG +import io + +def load_apng(file): + pass + +def load_webp(file): + pass + +def get_apng_duration(file): + img = APNG.open(file) + dur = 0 + + for frame, frame_info in img.frames: + dur += frame_info.delay*10 # it's in centiseconds, convert to milliseconds + + return dur + +def get_webp_duration(file): + img = Image.open(file) + dur = 0 + + for i in range(img.n_frames): + img.seek(i) + img.load() # strange thing with Pillow and animated webp's is that the img.info dictionary attr doesn't update unless you call a function like this + dur += img.info["duration"] + + return dur \ No newline at end of file