summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--photoblaster/_file.py9
-rwxr-xr-xphotoblaster/modules/pbbreaker/__init__.py2
-rw-r--r--photoblaster/modules/pbconcat/__init__.py50
-rwxr-xr-xphotoblaster/modules/pbgrid/__init__.py4
4 files changed, 33 insertions, 32 deletions
diff --git a/photoblaster/_file.py b/photoblaster/_file.py
index 88ac460..921c0ce 100644
--- a/photoblaster/_file.py
+++ b/photoblaster/_file.py
@@ -58,7 +58,7 @@ class File(object):
if self._is_temp:
namepart = "temp"
name += "%s_%s-%s" % (
- self._classname, self.get_creation_time(), random.randint(0,99)
+ self._classname, self.get_creation_time(), random.randint(0, 99)
)
if namepart:
name += "_%s" % namepart
@@ -120,11 +120,14 @@ class File(object):
sys.stderr.write("couldn't get gif frames\n")
raise e
- def choose_gif_frame(self, module=None):
+ def compress_to_single_frame(self, module=None, random=True):
_gif_frames = self.get_frames()
if len(_gif_frames) == 1:
return
- frame = random.choice(_gif_frames)
+ if random:
+ frame = random.choice(_gif_frames)
+ else:
+ frame = _gif_frames[0]
cmd = [BIN_CONVERT, frame.get_filepath(), self.get_filepath()]
call(cmd)
if module:
diff --git a/photoblaster/modules/pbbreaker/__init__.py b/photoblaster/modules/pbbreaker/__init__.py
index cda5658..bac5372 100755
--- a/photoblaster/modules/pbbreaker/__init__.py
+++ b/photoblaster/modules/pbbreaker/__init__.py
@@ -168,7 +168,7 @@ class PbBreaker(ModuleBase):
def _prepare_filedata(self):
if self.params.url.mimetype == "gif" and\
self.params.breaktype not in ['mat', 'psd']:
- self.params.url.get_file().choose_gif_frame(module=self)
+ self.params.url.get_file().compress_to_single_frame(module=self)
if self.params.breakangle:
self._rotate()
self._enforce_jpg()
diff --git a/photoblaster/modules/pbconcat/__init__.py b/photoblaster/modules/pbconcat/__init__.py
index 75d741e..e9bc671 100644
--- a/photoblaster/modules/pbconcat/__init__.py
+++ b/photoblaster/modules/pbconcat/__init__.py
@@ -4,14 +4,12 @@ from photoblaster._file import File
_DEFAULT_MODE = 'append'
-#todo
-#handle mimetype
-#make run faster
-
class PbConcat(ModuleBase):
example_params = {
'img_url1': "http://i.imgur.com/QGIplwA.gif",
- 'img_url2': "http://dump.fm/images/20100924/1285385385062-dumpfm-j1p2m3-animate.gif",
+ 'img_url2': (
+ "http://dump.fm/images/20100924/"
+ "1285385385062-dumpfm-j1p2m3-animate.gif"),
'username': 'donkey',
'mode': 'append',
'frames_match': 'longest',
@@ -53,28 +51,28 @@ class PbConcat(ModuleBase):
)
self._db_url_param = self.params.img_url1.url
- def _merge_frames(self, image1, image2):
- #order images in terms of frame count
- images = (image1, image2)
+ def _get_frames_of_equal_count(self, image_target, image_to_alter):
if self.params.finalformat in ["png", "jpg"]:
- image1.choose_gif_frame()
- image2.choose_gif_frame()
- if len(image2.get_frames()) > len(image1.get_frames()):
- images = (image2, image1)
- elif len(image2.get_frames()) == len(image1.get_frames()):
- #just merge the one file
- return self._concat_static(image1, image2)
- if self.params.frames_match == "longest":
- #additive
- frames = self._add_frames(
- images[1].get_frames(), len(images[0].get_frames()))
- #FIXME
- return self._concat_gif(images[0], self._frames_to_gif(frames))
- elif self.params.frames_match == "shortest":
- #subtractive
+ image_target.compress_to_single_frame()
+ image_to_alter.compress_to_single_frame()
+ return ([image_target], [image_to_alter])
+ to_alter_frames = image_to_alter.get_frames()
+ target_frames = image_target.get_frames()
+ if len(to_alter_frames) > len(target_frames):
frames = self._reduce_frames(
- images[0].get_frames(), len(images[1].get_frames()))
- return self._concat_gif(images[0], self._frames_to_gif(frames))
+ to_alter_frames, len(target_frames))
+ elif len(to_alter_frames) < len(target_frames):
+ frames = self._add_frames(
+ to_alter_frames, len(target_frames))
+ else:
+ frames = (target_frames, to_alter_frames)
+ return frames
+
+ def _merge_frames_of_equal_count(self, frames1, frames2):
+ frames = []
+ for i in xrange(0, len(frames1)):
+ frames.append(self._concat_static(frames1[i], frames2[i]))
+ return frames
def _match_dimensions(self):
dimensions1 = self.params.img_url1.get_file().get_dimensions()
@@ -180,7 +178,7 @@ class PbConcat(ModuleBase):
BIN_CONVERT,
"-size",
"x".join(image.get_dimensions()),
- "xc:white",
+ "xc:transparent",
canvasfile.get_filepath()])
self._call_cmd(cmd)
self._files_created.append(canvasfile)
diff --git a/photoblaster/modules/pbgrid/__init__.py b/photoblaster/modules/pbgrid/__init__.py
index 39686c7..38504bc 100755
--- a/photoblaster/modules/pbgrid/__init__.py
+++ b/photoblaster/modules/pbgrid/__init__.py
@@ -186,7 +186,7 @@ class PbGrid(ModuleBase):
def _prepare_gridimage(self, image):
if image['mimetype'] == 'gif':
- image.get_file().choose_gif_frame(module=self)
+ image.get_file().compress_to_single_frame(module=self)
if image['mimetype'] != 'png':
cmd = [
BIN_CONVERT,
@@ -195,7 +195,7 @@ class PbGrid(ModuleBase):
else:
cmd = [
'cp', image.get_file().get_filepath(),
- self.output_file.get_filepath()]
+ self.get_output_file().get_filepath()]
self._call_cmd(cmd)
def _overlay_planebgimage(self):