summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpepperpepperpepper <pepper@scannerjammer.com>2016-03-07 16:06:38 -0800
committerpepperpepperpepper <pepper@scannerjammer.com>2016-03-07 16:06:38 -0800
commitd80bfcf72620ac65008f18ca5bd4aa73523b4e5c (patch)
tree986c51ce6ae1889ba1bdd091c119e8d6a4b5c427
parent42a5e0d75cc69890beb8bb584c2894a5c15b8c0e (diff)
works great
-rw-r--r--photoblaster/config.py4
-rw-r--r--photoblaster/modules/pbconcat/__init__.py57
2 files changed, 38 insertions, 23 deletions
diff --git a/photoblaster/config.py b/photoblaster/config.py
index 76d465c..4977edf 100644
--- a/photoblaster/config.py
+++ b/photoblaster/config.py
@@ -63,3 +63,7 @@ if LOCAL:
DB_HOST = "localhost"
BASE_URL = "http://i.asdf.us"
+#so that dimensions concat size doesn't get too big
+PBCONCAT_DIMENSIONS_LIMIT = 700
+PBCONCAT_FRAMES_LIMIT = 20
+
diff --git a/photoblaster/modules/pbconcat/__init__.py b/photoblaster/modules/pbconcat/__init__.py
index 67f7f96..586fe43 100644
--- a/photoblaster/modules/pbconcat/__init__.py
+++ b/photoblaster/modules/pbconcat/__init__.py
@@ -1,21 +1,22 @@
from photoblaster.modules import ModuleBase
-from photoblaster.config import BIN_CONVERT, BIN_COMPOSITE, DEFAULT_FINALFORMAT
+from photoblaster.config import BIN_CONVERT, BIN_COMPOSITE, \
+ DEFAULT_FINALFORMAT, PBCONCAT_DIMENSIONS_LIMIT, PBCONCAT_FRAMES_LIMIT
from photoblaster._file import File
from subprocess import call
import copy
_DEFAULT_DIRECTION = 'right'
+
class SizeNotOkError(Exception):
pass
+
class PbConcatFile(File):
@classmethod
def from_file(cls, _file):
obj = copy.copy(_file)
obj.__class__ = PbConcatFile
- if not obj.is_size_ok():
- raise SizeNotOkError
return obj
def get_frames(self):
@@ -24,7 +25,7 @@ class PbConcatFile(File):
return self._frames_cache
def set_frames(self, frames):
- self._frames_cache = frames
+ self._frames_cache = frames
def get_dimensions(self):
if not hasattr(self, "_dimensions_cache"):
@@ -64,10 +65,13 @@ class PbConcatFile(File):
def is_size_ok(self):
ok = True
if any(
- [dimension > _MAX_DIMENSION for dimension in self.get_dimensions()]
- ) or len(self.get_frames()) > _MAX_FRAME_LENGTH:
+ [
+ dimension > PBCONCAT_DIMENSIONS_LIMIT
+ for dimension in self.get_dimensions()
+ ]
+ ) or len(self.get_frames()) > PBCONCAT_FRAMES_LIMIT:
ok = False
- return ok
+ return ok
class PbConcat(ModuleBase):
@@ -125,15 +129,18 @@ class PbConcat(ModuleBase):
self.set_output_file(
PbConcatFile.from_file(output_file)
)
- self.params.img_url1.set_file(
- PbConcatFile.from_file(self.params.img_url1.get_file())
- )
- self.params.img_url2.set_file(
- PbConcatFile.from_file(self.params.img_url2.get_file())
- )
+ im1_file = PbConcatFile.from_file(self.params.img_url1.get_file())
+ im2_file = PbConcatFile.from_file(self.params.img_url2.get_file())
+ try:
+ im1_file.is_size_ok()
+ im2_file.is_size_ok()
+ except SizeNotOkError:
+ self.cleanup()
+ raise
+ self.params.img_url1.set_file(im1_file)
+ self.params.img_url2.set_file(im2_file)
self._db_url_param = self.params.img_url1.url
-
def _make_frames_count_equal(self):
im1 = self.params.img_url1.get_file()
im2 = self.params.img_url2.get_file()
@@ -141,8 +148,9 @@ class PbConcat(ModuleBase):
im1.compress_to_single_frame()
im2.compress_to_single_frame()
return
- im_shorter = im1 if len(im1.get_frames()) < len(im2.get_frames()) else im2
- im_longer = im2 if im_shorter == im1 else im1
+ im_shorter = im1 if len(
+ im1.get_frames()) < len(im2.get_frames()) else im2
+ im_longer = im2 if im_shorter == im1 else im1
if self.params.frames_match == "shorter":
im_longer.reduce_frames(len(im_shorter.get_frames()))
else:
@@ -161,21 +169,24 @@ class PbConcat(ModuleBase):
im2 = self.params.img_url2.get_file()
"""if merging right, match height, else width
"""
- dimensions_idx = 1 if self.params.merge_direction == "right" else 0
- dimension_name = "height" if self.params.merge_direction == "right" else "width"
+ dimensions_idx = 1 if self.params.merge_direction == "right" \
+ else 0
+ dimension_name = "height" if self.params.merge_direction == "right" \
+ else "width"
#if heights are the same, return
- if im1.get_dimensions()[dimensions_idx] == im2.get_dimensions()[dimensions_idx]:
+ if im1.get_dimensions()[dimensions_idx] == im2.get_dimensions()[
+ dimensions_idx]:
return
is_im1_larger = True if im1.get_dimensions()[dimensions_idx] > \
im2.get_dimensions()[dimensions_idx] and \
- self.params.dimensions_match == "smaller" else False #flips logic
+ self.params.dimensions_match == "smaller" else False # flips logic
- im_scale, im_scale_by = (im1, im2) if is_im1_larger else (im2, im1)
+ im_scale, im_scale_by = (im1, im2) if is_im1_larger else (im2, im1)
im_scale.resize(**{
dimension_name: im_scale_by.get_dimensions()[dimensions_idx],
'module': self
})
-
+
def _concat_static(self, image1, image2):
tempfile = File(
is_temp=True,
@@ -205,7 +216,7 @@ class PbConcat(ModuleBase):
self._match_dimensions()
self._make_frames_count_equal()
self._merge_frames()
- self._finalize_image()
+ self._finalize_image()
super(PbConcat, self).create()
def _add_canvas(self, image, canvas_color="transparent"):