summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpepperpepperpepper <pepper@scannerjammer.com>2016-03-03 05:33:31 -0800
committerpepperpepperpepper <pepper@scannerjammer.com>2016-03-03 05:33:31 -0800
commitac7b96db4244bd43a3b909a7ebcf8327c7cf170b (patch)
treef99dfc7a5b6671cf876e33f042639d5864fc8fac
parent87f86bec377ece3fa5efe7eb9922497f804e92ae (diff)
adding gifs to concat
-rw-r--r--photoblaster/_file.py5
-rw-r--r--photoblaster/modules/pbconcat/__init__.py81
-rw-r--r--photoblaster/modules/pbconcat/append.sh23
-rw-r--r--run_module_examples.py2
4 files changed, 67 insertions, 44 deletions
diff --git a/photoblaster/_file.py b/photoblaster/_file.py
index 370a6c3..4343c8a 100644
--- a/photoblaster/_file.py
+++ b/photoblaster/_file.py
@@ -70,6 +70,7 @@ class File(object):
"""sets the filepath"""
if os.path.exists(self.get_filepath()):
cmd = ['mv', self.get_filepath(), filepath]
+ call(cmd)
if module:
module.commands.append(" ".join(cmd))
self.set_filename(filename=os.path.basename(filepath))
@@ -165,7 +166,7 @@ class File(object):
"Couldn't determine filesize of %s\n" % self.get_filepath())
sys.stderr.write("%s\n" % e)
- def resize(self, width, height, module=None):
+ def resize(self, width="", height="", module=None):
cmd = [
BIN_CONVERT,
self.get_filepath(),
@@ -174,4 +175,4 @@ class File(object):
self.get_filepath()]
call(cmd)
if module:
- module.commands.append(cmd)
+ module.commands.append(" ".join(cmd))
diff --git a/photoblaster/modules/pbconcat/__init__.py b/photoblaster/modules/pbconcat/__init__.py
index 655d16b..f2171f5 100644
--- a/photoblaster/modules/pbconcat/__init__.py
+++ b/photoblaster/modules/pbconcat/__init__.py
@@ -1,23 +1,23 @@
from photoblaster.modules import ModuleBase
-from photoblaster.config import BIN_CONVERT, BIN_COMPOSITE
+from photoblaster.config import BIN_CONVERT, BIN_COMPOSITE, DEFAULT_FINALFORMAT
from photoblaster._file import File
_DEFAULT_MODE = 'append'
#todo
-#make this thing concat two pngs
-#then a png + a gif
+#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'
+ 'img_url1': "http://i.asdf.us/im/2e/PbConcat_1456981685_donkey.png",
+ 'img_url2': "http://i.asdf.us/im/6f/PbConcat_1456981587_donkey.png",
+ 'username': 'donkey',
+ 'mode': 'append',
+ 'frames_match': 'longest',
+ 'finalformat': 'jpg'
}
except:
example_params = {}
@@ -32,6 +32,16 @@ class PbConcat(ModuleBase):
'enum_values': ['append', 'stack'],
'default': _DEFAULT_MODE
},
+ 'frames_match': {
+ 'type': 'enum',
+ 'enum_values': ['longest', 'shortest'],
+ 'default': 'shortest'
+ },
+ 'finalformat': {
+ 'type': 'enum',
+ 'enum_values': ['png', 'gif', 'jpg'],
+ 'default': DEFAULT_FINALFORMAT
+ },
'username': {'type': 'string'},
}
self.params.definitions_import(
@@ -50,19 +60,25 @@ class PbConcat(ModuleBase):
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]:
+ if self.params.mode == "append" and \
+ dimensions1[1] != dimensions2[1]:
self.params.img_url2.get_file().resize(
- dimensions2[0], dimensions1[1]
- )
+ height=dimensions1[1],
+ module=self
+ ) # make heights the same
+ if self.params.mode == "stack" and \
+ dimensions1[0] != dimensions2[0]:
+ self.params.img_url2.get_file().resize(
+ width=dimensions1[0],
+ module=self
+ ) # make widths the same
def _concat_static(self, image1, image2):
tempfile = File(
is_temp=True,
extension="png",
)
+ cmd = []
if self.params.mode == "stack":
cmd = [
BIN_CONVERT,
@@ -79,7 +95,31 @@ class PbConcat(ModuleBase):
cmd += ['-dispose', '2']
cmd += ['-loop', '0']
cmd += frames
- cmd += [self.output_file.get_filepath()]
+ cmd += [self.get_output_file().get_filepath()]
+ self._call_cmd(cmd)
+
+ def _add_canvas(self, imageparam):
+ """maybe remove"""
+ canvasfile = File(
+ is_temp=True,
+ extension=imageparam.mimetype,
+ classname=self.__class__.__name__
+ )
+ cmd = ([
+ BIN_CONVERT,
+ "-size",
+ "x".join(imageparam.get_file().get_dimensions()),
+ "xc:white",
+ canvasfile.get_filepath()])
+ self._call_cmd(cmd)
+ self._files_created.append(canvasfile)
+ cmd = ([
+ BIN_COMPOSITE,
+ "-gravity",
+ "center",
+ imageparam.get_file().get_filepath(),
+ canvasfile.get_filepath(),
+ imageparam.get_file().get_filepath()])
self._call_cmd(cmd)
def add_frames(frames, frame_number):
@@ -93,12 +133,17 @@ class PbConcat(ModuleBase):
return new_frames
def create(self):
+ #for imageparam in [self.params.img_url1, self.params.img_url2]:
+ # if getattr(imageparam, "mimetype") in ["gif", "png"]:
+ # self._add_canvas(imageparam)
self._match_dimensions()
- self.set_output_file(
- self._concat_static(
+ tempfile = self._concat_static(
self.params.img_url1.get_filepath(),
self.params.img_url2.get_filepath(),
- )
+ )
+ tempfile.set_filepath(
+ self.get_output_file().get_filepath(),
+ module=self
)
super(PbConcat, self).create()
diff --git a/photoblaster/modules/pbconcat/append.sh b/photoblaster/modules/pbconcat/append.sh
deleted file mode 100644
index acccb61..0000000
--- a/photoblaster/modules/pbconcat/append.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#!/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*
diff --git a/run_module_examples.py b/run_module_examples.py
index 342892b..27fd13c 100644
--- a/run_module_examples.py
+++ b/run_module_examples.py
@@ -4,7 +4,7 @@ from photoblaster.modules import Modules
modules = Modules()
for module_name in modules.list_modules():
- if module_name == "pblandscape":
+ if module_name == "pbconcat":
print "\n\n\n"
print "running example for %s" % module_name
cls = modules.get_module(module_name)