summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--photoblaster/_file.py15
-rw-r--r--photoblaster/modules/pbconcat/__init__.py122
-rw-r--r--photoblaster/modules/pbconcat/append.sh23
3 files changed, 158 insertions, 2 deletions
diff --git a/photoblaster/_file.py b/photoblaster/_file.py
index 5b51acc..370a6c3 100644
--- a/photoblaster/_file.py
+++ b/photoblaster/_file.py
@@ -5,8 +5,8 @@ import sha
import sys
import time
from subprocess import Popen, PIPE, call
-from photoblaster.config import WORKING_DIR, BIN_IDENTIFY, DEFAULT_WIDTH, \
- DEFAULT_HEIGHT, BIN_CONVERT, LOCAL, BASE_URL, DEFAULT_FINALFORMAT
+from photoblaster.config import WORKING_DIR, BIN_IDENTIFY, \
+ BIN_CONVERT, BASE_URL, DEFAULT_FINALFORMAT
_MAX_FILENAME_LENGTH = 20
@@ -164,3 +164,14 @@ class File(object):
sys.stderr.write(
"Couldn't determine filesize of %s\n" % self.get_filepath())
sys.stderr.write("%s\n" % e)
+
+ def resize(self, width, height, module=None):
+ cmd = [
+ BIN_CONVERT,
+ self.get_filepath(),
+ "-resize",
+ "%sx%s" % (width, height),
+ self.get_filepath()]
+ call(cmd)
+ if module:
+ module.commands.append(cmd)
diff --git a/photoblaster/modules/pbconcat/__init__.py b/photoblaster/modules/pbconcat/__init__.py
new file mode 100644
index 0000000..655d16b
--- /dev/null
+++ b/photoblaster/modules/pbconcat/__init__.py
@@ -0,0 +1,122 @@
+from photoblaster.modules import ModuleBase
+from photoblaster.config import BIN_CONVERT, BIN_COMPOSITE
+from photoblaster._file import File
+_DEFAULT_MODE = 'append'
+
+
+#todo
+#make this thing concat two pngs
+#then a png + a gif
+#then two gifs
+
+
+class PbConcat(ModuleBase):
+ try:
+ example_params = {
+ 'img_url1': (
+ "http://i.asdf.us/im/28/"
+ "imgrid_1347572454_imgrid_1347572408_xx_abridged____.png"),
+ 'img_url2': "http://i.asdf.us/im/cf/imgrid_1340161989_pepper.png",
+ 'username': 'donkey'
+ }
+ except:
+ example_params = {}
+
+ def __init__(self, **kwargs):
+ super(PbConcat, self).__init__(**kwargs)
+ _definitions = {
+ 'img_url1': {'type': 'img_url'},
+ 'img_url2': {'type': 'img_url'},
+ 'mode': {
+ 'type': 'enum',
+ 'enum_values': ['append', 'stack'],
+ 'default': _DEFAULT_MODE
+ },
+ 'username': {'type': 'string'},
+ }
+ self.params.definitions_import(
+ _definitions,
+ kwargs,
+ classname=self.__class__.__name__)
+ self.set_output_file(
+ File(
+ classname=self.__class__.__name__,
+ extension="png",
+ username=self.params.username
+ )
+ )
+ self._db_url_param = self.params.img_url1.url
+
+ def _match_dimensions(self):
+ dimensions1 = self.params.img_url1.get_file().get_dimensions()
+ dimensions2 = self.params.img_url2.get_file().get_dimensions()
+ dimensions_idx = 1 # make heights the same
+ if self.params.mode == "stack":
+ dimensions_idx = 0 # make widths the same
+ if dimensions1[dimensions_idx] != dimensions2[dimensions_idx]:
+ self.params.img_url2.get_file().resize(
+ dimensions2[0], dimensions1[1]
+ )
+
+ def _concat_static(self, image1, image2):
+ tempfile = File(
+ is_temp=True,
+ extension="png",
+ )
+ if self.params.mode == "stack":
+ cmd = [
+ BIN_CONVERT,
+ image1, image2, "-append", tempfile.get_filepath()]
+ else:
+ cmd = [
+ BIN_CONVERT,
+ image1, image2, "+append", tempfile.get_filepath()]
+ self._call_cmd(cmd)
+ return tempfile
+
+ def _frames_to_gif(self, frames):
+ cmd = [BIN_CONVERT]
+ cmd += ['-dispose', '2']
+ cmd += ['-loop', '0']
+ cmd += frames
+ cmd += [self.output_file.get_filepath()]
+ self._call_cmd(cmd)
+
+ def add_frames(frames, frame_number):
+ """
+ adds frames to a gif to make it the same length as another gif
+ """
+ new_frames = []
+ for i in xrange(0, int(frame_number/len(frames))):
+ new_frames += frames
+ new_frames += frames[0:(frame_number % len(frames))]
+ return new_frames
+
+ def create(self):
+ self._match_dimensions()
+ self.set_output_file(
+ self._concat_static(
+ self.params.img_url1.get_filepath(),
+ self.params.img_url2.get_filepath(),
+ )
+ )
+ super(PbConcat, self).create()
+
+# def run_concat(image1, image2):
+# frames1 = gif_frames(image1)
+# frames2 = gif_frames(image2)
+# if len(frames1) == 1 and len(frames2) == 1:
+# return concat_static(image1, image2)
+# if len(frames1) > len(frames2):
+# frames2 = add_frames(frames2, len(frames1))
+# elif len(frames1) < len(frames2):
+# frames1 = add_frames(frames1, len(frames2))
+# final_frames = []
+# for i in xrange(0, len(frames1)):
+# final_frames.append(concat_static(frames1[i], frames2[i]))
+# OUTFILE = frames_to_gif(final_frames)
+# return OUTFILE
+
+
+def get_class():
+ return PbConcat
diff --git a/photoblaster/modules/pbconcat/append.sh b/photoblaster/modules/pbconcat/append.sh
new file mode 100644
index 0000000..acccb61
--- /dev/null
+++ b/photoblaster/modules/pbconcat/append.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+# $1 : first gif
+# $2 : second gif
+
+mkdir first
+cd first
+convert $1 x%04d.gif
+cd ..
+mkdir second
+cd second
+convert $2 x%04d.gif
+cd ..
+
+for filename in first/*
+do
+ filename=`basename $filename`
+ montage -tile 2x1 -geometry 512x512 first/$filename second/$filename concat$filename
+done
+convert concat* output.gif
+
+rm -rf first
+rm -rf second
+rm concat*