summaryrefslogtreecommitdiff
path: root/Pb/__init__.py
diff options
context:
space:
mode:
Diffstat (limited to 'Pb/__init__.py')
-rw-r--r--Pb/__init__.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/Pb/__init__.py b/Pb/__init__.py
index 586b363..ff0a764 100644
--- a/Pb/__init__.py
+++ b/Pb/__init__.py
@@ -55,18 +55,6 @@ class Pb(object):
except Exception:
raise Exception("Unable to call cmd {}".format(str(cmd)))
- @staticmethod
- def gif_frames(filepath):
- try:
- info = Popen([BIN_IDENTIFY,filepath], stdout=PIPE).communicate()[0]
- frames = filter((lambda x: x), map(
- (lambda x: x.split(" ")[0]),
- (info).split('\n')
- ))
- return frames
- except Exception as e:
- self.err_warn("couldn't get gif frames")
- raise e;
@staticmethod
def dimensions (filepath):
@@ -100,6 +88,7 @@ class Pb(object):
sys.stderr.write("ERROR:{} - {}\n".format(self.__class__.__name__, s))
def _cleanup(self):
+ if not self._files_created: return
cmd = ["rm"]+self._files_created
self._call_cmd(cmd)
@@ -119,3 +108,20 @@ class Pb(object):
sys.stderr.write("files created %s\n" % b._files_created)
sys.stderr.write("commands %s" % " ".join(b.commands))
+ @staticmethod
+ def gif_frames(filepath):
+ try:
+ info = Popen([BIN_IDENTIFY,filepath], stdout=PIPE).communicate()[0]
+ frames = filter((lambda x: x), map(
+ (lambda x: x.split(" ")[0]),
+ (info).split('\n')
+ ))
+ return frames
+ except Exception as e:
+ self.err_warn("couldn't get gif frames")
+ raise e;
+
+ def _choose_gif_frame(self, filepath):
+ _gif_frames = Pb.gif_frames(filepath)
+ frame = random.choice(_gif_frames)
+ self._call_cmd([BIN_CONVERT, frame, filepath])