diff options
| -rw-r--r-- | photoblaster/_file.py | 11 | ||||
| -rw-r--r-- | photoblaster/modules/.ropeproject/globalnames | bin | 494 -> 482 bytes | |||
| -rwxr-xr-x | photoblaster/modules/pbbreaker.py | 2 | ||||
| -rwxr-xr-x | photoblaster/modules/pbgenerate.py | 21 | ||||
| -rwxr-xr-x | photoblaster/modules/pbgrid.py | 72 | ||||
| -rwxr-xr-x | photoblaster/modules/pblandscape/__init__.py | 17 | ||||
| -rwxr-xr-x | photoblaster/modules/pbpattern.py | 83 | ||||
| -rw-r--r-- | photoblaster/param/img_url.py | 2 | ||||
| -rw-r--r-- | run_module_examples.py | 2 |
9 files changed, 135 insertions, 75 deletions
diff --git a/photoblaster/_file.py b/photoblaster/_file.py index bd043b8..b370bb4 100644 --- a/photoblaster/_file.py +++ b/photoblaster/_file.py @@ -5,7 +5,7 @@ import sha import sys import time from photoblaster.s3.cli import S3Cli -from subprocess import Popen, PIPE +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 @@ -121,10 +121,13 @@ class File(object): sys.stderr.write("couldn't get gif frames\n") raise e - def _choose_gif_frame(self): - _gif_frames = self.gif_frames(self._filepath) + def choose_gif_frame(self, module=None): + _gif_frames = self.gif_frames(self.get_filepath()) frame = random.choice(_gif_frames) - self._call_cmd([BIN_CONVERT, frame, self._filepath]) + cmd = [BIN_CONVERT, frame, self.get_filepath()] + call(cmd) + if module: + module.commands.append(" ".join(cmd)) def as_dict(self): url = "%s/im/%s/%s" % (BASE_URL, self._hashdir, self.get_filename()) diff --git a/photoblaster/modules/.ropeproject/globalnames b/photoblaster/modules/.ropeproject/globalnames Binary files differindex bf1ed49..795a9f6 100644 --- a/photoblaster/modules/.ropeproject/globalnames +++ b/photoblaster/modules/.ropeproject/globalnames diff --git a/photoblaster/modules/pbbreaker.py b/photoblaster/modules/pbbreaker.py index 94bfb3c..d282513 100755 --- a/photoblaster/modules/pbbreaker.py +++ b/photoblaster/modules/pbbreaker.py @@ -168,7 +168,7 @@ class PbBreaker(Pb): def _prepare_filedata(self): if self.params.url.mimetype == "gif" and\ self.params.breaktype not in ['mat', 'psd']: - self._choose_gif_frame(self.params.url.path) + self.params.url.get_file().choose_gif_frame(module=self) if self.params.breakangle: self._rotate() self._enforce_jpg() diff --git a/photoblaster/modules/pbgenerate.py b/photoblaster/modules/pbgenerate.py index c034a6f..1dd264b 100755 --- a/photoblaster/modules/pbgenerate.py +++ b/photoblaster/modules/pbgenerate.py @@ -2,6 +2,7 @@ from photoblaster.config import BIN_CONVERT, OUTPUT_IMAGE_TYPES,\ DEFAULT_FINALFORMAT from photoblaster.modules import Pb +from photoblaster._file import File _GRAVITY_PARAMS = [ "NorthWest", "North", "NorthEast", "West", @@ -123,9 +124,13 @@ class PbGenerate(Pb): elif self.params.transparent: self.tag = "%s:%s" % (self.tag, "transparent") - self.newfile = File() - self.filename, self.filepath = self._filename_filepath_create( - url=self.params.url['url'], extension=self.params.format + self.set_output_file( + File.from_url( + self.params.url['url'], + username=self.params.username, + classname=self.__class__.__name__, + extension=self.params.format + ) ) self._db_url_param = str(self.params.url['url']) @@ -133,18 +138,18 @@ class PbGenerate(Pb): def _composite(self): """Imagemagick composite command""" cmd = [ - BIN_CONVERT, self.params.background['path'], - "null:", self.filepath, "-matte", + BIN_CONVERT, self.params.background.get_file().get_filepath(), + "null:", self.get_output_file().get_filepath(), "-matte", "-dispose", self.params.dispose, "-gravity", self.params.gravity, "-compose", self.params.compose, "-layers", "composite", - self.filepath + self.get_output_file().get_filepath() ] self._call_cmd(cmd) def _convert(self): """Imagemagick convert command""" - cmd = [BIN_CONVERT, self.params.url['path']] + cmd = [BIN_CONVERT, self.params.url.get_file().get_filepath()] if self.params.rotate: cmd += ["-rotate", self.params.rotate] if self.params.flip: @@ -185,7 +190,7 @@ class PbGenerate(Pb): ) ] cmd.append("-coalesce") # why? FIXME - cmd += [self.filepath] + cmd += [self.get_output_file().get_filepath()] self._call_cmd(cmd) def create(self): diff --git a/photoblaster/modules/pbgrid.py b/photoblaster/modules/pbgrid.py index cb4eefb..c43c4b1 100755 --- a/photoblaster/modules/pbgrid.py +++ b/photoblaster/modules/pbgrid.py @@ -20,6 +20,7 @@ class PbGrid(Pb): 'hlines': 'true', 'roll': '30', 'shadow': 'true', + 'username': 'someuser', 'trim': 'true' } @@ -64,24 +65,27 @@ class PbGrid(Pb): _definitions, kwargs, classname=self.__class__.__name__ ) if self.params.imageinstead: - self.output_file = File.from_url( - self.params.imageinstead['url'], - extension=self.params.finalformat, - classname=self.__class__.__name__, - username=self.params.username + self.set_output_file( + File.from_url( + self.params.imageinstead['url'], + extension=self.params.finalformat, + classname=self.__class__.__name__, + username=self.params.username) ) elif self.params.planebgimage: - self.output_file = File.from_url( - self.params.planebgimage['url'], - extension=self.params.finalformat, - classname=self.__class__.__name__, - username=self.params.username + self.set_output_file( + File.from_url( + self.params.planebgimage['url'], + extension=self.params.finalformat, + classname=self.__class__.__name__, + username=self.params.username) ) else: - self.output_file = File( - extension=self.params.finalformat, - classname=self.__class__.__name__, - username=self.params.username + self.set_output_file( + File( + extension=self.params.finalformat, + classname=self.__class__.__name__, + username=self.params.username) ) self._db_url_param = str( @@ -106,7 +110,8 @@ class PbGrid(Pb): bgcolor = "xc:{}".format(self.params.bgcolor or 'transparent') cmd = [ BIN_CONVERT, - "-size", dimensions, bgcolor, self.output_file.get_filepath()] + "-size", dimensions, bgcolor, + self.get_output_file().get_filepath()] self._call_cmd(cmd) #2nd step-- run grid @@ -127,8 +132,8 @@ class PbGrid(Pb): if self.params.opacity: cmd += ['-o', self.params.opacity] cmd += [ - self.output_file.get_filepath(), - self.output_file.get_filepath()] + self.get_output_file().get_filepath(), + self.get_output_file().get_filepath()] self._call_cmd(cmd) def _shadow_cmd(self): @@ -139,11 +144,11 @@ class PbGrid(Pb): """ cmd = [ BIN_CONVERT, - self.output_file.get_filepath(), + self.get_output_file().get_filepath(), "(", "+clone", "-background", "black", "-shadow", "100x2+20+10", ")", "+swap", "-background", "none", "-layers", "merge", "+repage", - self.output_file.get_filepath() + self.get_output_file().get_filepath() ] self._call_cmd(cmd) @@ -168,32 +173,40 @@ class PbGrid(Pb): if self.params.transition: cmd += ["vp={}".format(self.params.transition)] cmd += [ - self.output_file.get_filepath(), self.output_file.get_filepath()] + self.get_output_file().get_filepath(), + self.get_output_file().get_filepath()] self._call_cmd(cmd) def _trim_cmd(self): cmd = [ BIN_CONVERT, - self.output_file.get_filepath(), - "-trim", "+repage", self.output_file.get_filepath()] + self.get_output_file().get_filepath(), + "-trim", "+repage", self.get_output_file().get_filepath()] self._call_cmd(cmd) def _prepare_gridimage(self, image): if image['mimetype'] == 'gif': - _frame = self._choose_gif_frame(image['path']) + image.get_file().choose_gif_frame(module=self) if image['mimetype'] != 'png': - cmd = [BIN_CONVERT, image['path'], self.output_file.get_filepath()] + cmd = [ + BIN_CONVERT, + image.get_file().get_filepath(), + self.get_output_file().get_filepath()] else: - cmd = ['cp', image['path'], self.output_file.get_filepath()] + cmd = [ + 'cp', image.get_file().get_filepath(), + self.output_file.get_filepath()] self._call_cmd(cmd) def _overlay_planebgimage(self): + import sys + sys.stderr.write("should be overlaying here!\n\n\n") cmd = [ BIN_COMPOSITE, "-compose", "Dst_Over", "-gravity", "center", self.params.planebgimage["path"], - self.output_file.get_filepath(), - self.output_file.get_filepath() + self.get_output_file().get_filepath(), + self.get_output_file().get_filepath() ] self._call_cmd(cmd) @@ -210,7 +223,12 @@ class PbGrid(Pb): self._shadow_cmd() self._threed_rotate_cmd() if self.params.planebgimage: + import sys + sys.stderr.write("what the fuck!!!") self._overlay_planebgimage() + else: + import sys + sys.stderr.write("UMMMMMMMMMMMMMMMMMM\n") if self.params.trim: self._trim_cmd() super(PbGrid, self).create() diff --git a/photoblaster/modules/pblandscape/__init__.py b/photoblaster/modules/pblandscape/__init__.py index b03dce0..3044b3b 100755 --- a/photoblaster/modules/pblandscape/__init__.py +++ b/photoblaster/modules/pblandscape/__init__.py @@ -2,7 +2,7 @@ import base64 from photoblaster.modules import Pb import urlparse import re - +from photoblaster._file import File class PbLandscape(Pb): try: @@ -28,11 +28,15 @@ class PbLandscape(Pb): _definitions, kwargs, classname=self.__class__.__name__) - _namepart = re.sub(r'https?:?/?/?', '', str(self.params.texture)) - self.filename, self.filepath = self._filename_filepath_create( - url=_namepart, extension="png" + namepart = re.sub(r'https?:?/?/?', '', str(self.params.texture)) + self.set_output_file( + File( + namepart=namepart, + classname=self.__class__.__name__, + extension="png", + username=self.params.username + ) ) - self._db_url_param = str(self.params.texture) def _saveImgData(self): @@ -43,7 +47,8 @@ class PbLandscape(Pb): # Do something smart with charset and b64 instead of assuming plaindata = base64.b64decode(data) - with open(self.filepath, 'wb') as f: + with open( + self.get_output_file().get_filepath(), 'wb') as f: f.write(plaindata) except Exception as e: self.err_warn(str(e)) diff --git a/photoblaster/modules/pbpattern.py b/photoblaster/modules/pbpattern.py index ccf6963..1e80647 100755 --- a/photoblaster/modules/pbpattern.py +++ b/photoblaster/modules/pbpattern.py @@ -1,39 +1,54 @@ from photoblaster.config import BIN_CONVERT, BIN_COMPOSITE from photoblaster.modules import Pb from PIL import Image +from photoblaster._file import File + +_FUSE_MODE = "Pin_Light" -_FUSE_MODE="Pin_Light" class PbPattern(Pb): example_params = { - "pattern_data" : '{"matrix":[["0","0","0","0","0","1","0","0","0","0"],["0","0","0","0","1","1","1","0","0","0"],["0","0","1","1","1","0","1","0","0","0"],["0","1","1","0","0","0","0","0","0","0"],["0","1","0","0","1","0","0","0","0","0"],["0","1","0","0","1","0","0","0","1","0"],["0","1","0","0","1","1","0","0","1","0"],["0","1","0","0","0","1","1","1","1","0"],["0","1","1","1","1","0","0","0","0","0"],["0","0","0","0","1","0","0","0","0","0"]],"width":"10","height":"10"}', - "image_url" : "http://i.asdf.us/im/be/PinkHijab_1425078647_reye.gif", -# "username" : "garfield", -# "pattern_url" : "http://asdf.us/impattern/patterns/1.png", + "pattern_data": '{"matrix":[["0","0","0","0","0","1","0","0","0","0"],["0","0","0","0","1","1","1","0","0","0"],["0","0","1","1","1","0","1","0","0","0"],["0","1","1","0","0","0","0","0","0","0"],["0","1","0","0","1","0","0","0","0","0"],["0","1","0","0","1","0","0","0","1","0"],["0","1","0","0","1","1","0","0","1","0"],["0","1","0","0","0","1","1","1","1","0"],["0","1","1","1","1","0","0","0","0","0"],["0","0","0","0","1","0","0","0","0","0"]],"width":"10","height":"10"}', + #"username": "garfield", + #"pattern_url": "http://asdf.us/impattern/patterns/1.png", + "image_url": "http://i.asdf.us/im/be/PinkHijab_1425078647_reye.gif", } + def __init__(self, **kwargs): super(PbPattern, self).__init__(**kwargs) _definitions = { - 'image_url': {'type':'img_url'}, - 'pattern_url': {'type':'img_url'}, - 'pattern_data': {'type':'json'}, - 'username': {'type':'string'}, + 'image_url': {'type': 'img_url'}, + 'pattern_url': {'type': 'img_url'}, + 'pattern_data': {'type': 'json'}, + 'username': {'type': 'string'}, } - self.params.definitions_import(_definitions, kwargs, classname=self.__class__.__name__) - self.filename, self.filepath = self._filename_filepath_create( - url=self.params.image_url['url'], extension=self.params.image_url['mimetype'] + self.params.definitions_import( + _definitions, kwargs, classname=self.__class__.__name__) + self.set_output_file( + File.from_url( + self.params.image_url['url'], + extension=self.params.image_url['mimetype'], + classname=self.__class__.__name__, + username=self.params.username + ) ) + self.pattern_file = None if self.params.pattern_data: - _pattern_filename, self._pattern_filepath = self._filename_filepath_create(namepart="pattern") + self.pattern_file = File( + namepart="pattern", + username=self.params.username, + classname=self.__class__.__name__, + extension="png" + ) self._from_pattern_data() elif not self.params.pattern_url: - self.err_warn("pattern must be supplied as json array or as a png url") + self.err_warn( + "pattern must be supplied as json array or as a png url") else: - self._pattern_filepath = self.params.pattern_url['path'] + self.pattern_file = self.params.pattern_url.get_file() self._db_url_param = str(self.params.image_url.url) - def _from_pattern_data(self): def boolToColor(boolean): if boolean: @@ -48,34 +63,48 @@ class PbPattern(Pb): for i in range(0, len(specs['matrix'])): for j in range(0, len(specs['matrix'][i])): pixels[j, i] = boolToColor(int(specs['matrix'][i][j])) - - img.save(self._pattern_filepath, "PNG") + img.save(self.pattern_file.get_filepath(), "PNG") #first step def _make_canvas(self): - _width, _height = self._dimensions(self.params.image_url['path']) # same here - cmd = [BIN_CONVERT, "-size", _width + "x" + _height, "canvas:transparent", self.filepath] + _width, _height = self.params.image_url.get_file().get_dimensions() + cmd = [ + BIN_CONVERT, "-size", _width + "x" + _height, + "canvas:transparent", + self.get_output_file().get_filepath()] self._call_cmd(cmd) #second step use the Canvas as a background def _make_mask(self): #tile the pattern pattern on the canvas - cmd = [BIN_COMPOSITE, "-tile", self._pattern_filepath, self.filepath, self.filepath] + cmd = [ + BIN_COMPOSITE, "-tile", self.pattern_file.get_filepath(), + self.get_output_file().get_filepath(), + self.get_output_file().get_filepath()] self._call_cmd(cmd) #fuse the tiled file to create a mask - #convert thebg.gif -compose Dst_In null: thefile.gif -matte -layers composite new.gif + #convert thebg.gif -compose Dst_In null: \ + #thefile.gif -matte -layers composite new.gif cmd = [ - BIN_CONVERT, self.filepath, "-compose", "Dst_In", "null:", - self.params.image_url['path'], "-matte", "-layers", "composite", self.filepath + BIN_CONVERT, + self.get_output_file().get_filepath(), + "-compose", "Dst_In", "null:", + self.params.image_url.get_file().get_filepath(), + "-matte", "-layers", "composite", + self.get_output_file().get_filepath() + ] self._call_cmd(cmd) #third step def _fuse_mask(self, fuse_mode=_FUSE_MODE): cmd = [ - BIN_CONVERT, "-dispose", "2", self.filepath, "null:", - self.params.image_url['path'], "-matte", "-compose", fuse_mode, "-layers", "composite", - self.filepath + BIN_CONVERT, "-dispose", "2", + self.get_output_file().get_filepath(), + "null:", + self.params.image_url.get_file().get_filepath(), + "-matte", "-compose", fuse_mode, "-layers", "composite", + self.get_output_file().get_filepath() ] self._call_cmd(cmd) diff --git a/photoblaster/param/img_url.py b/photoblaster/param/img_url.py index 9285ecb..a6227e1 100644 --- a/photoblaster/param/img_url.py +++ b/photoblaster/param/img_url.py @@ -50,7 +50,7 @@ class Img_url(Param): return str(self.__dict__()) def __nonzero__(self): - return True if self.path and self.mimetype else False + return True if self.get_file() and self.mimetype else False def _image_download(self, url): """downloads the image to the path specified in the local diff --git a/run_module_examples.py b/run_module_examples.py index 882de78..3c0e29a 100644 --- a/run_module_examples.py +++ b/run_module_examples.py @@ -3,7 +3,7 @@ from photoblaster.modules import Pb for cls in Pb.__subclasses__(): print cls.__name__ - if cls.__name__ == "PbBreaker": + if cls.__name__ == "PbLandscape": instance = cls.example_run() print instance.get_output_file().as_dict() instance.get_output_file().s3move() |
