diff options
| author | yo mama <pepper@scannerjammer.com> | 2015-05-01 10:27:35 -0700 |
|---|---|---|
| committer | yo mama <pepper@scannerjammer.com> | 2015-05-01 10:27:35 -0700 |
| commit | ed134d6412c3ee32357f0582ee095f61210d637b (patch) | |
| tree | 437fe8cb5b6722662362f482dad1a93ff3abcdb8 | |
| parent | ceb902d57f97b4deef9591aeb3caf22bb7d6450b (diff) | |
ok just testing generate
| -rwxr-xr-x | generate.py | 144 | ||||
| -rw-r--r-- | move_to_server | 5 |
2 files changed, 63 insertions, 86 deletions
diff --git a/generate.py b/generate.py index fa0ea72..1bc1655 100755 --- a/generate.py +++ b/generate.py @@ -1,8 +1,6 @@ #!/usr/bin/python2.7 import sys import os -import re -import sha from pb.config import * import pb.lib.utils as utils @@ -12,19 +10,19 @@ LIKE_A_BOSS = "ryz pepper seamonkey JAMES".split(" ") DEFAULT_FINALFORMAT = "gif" DB_TAG = "pb"; -GRAVITY = "NorthWest North NorthEast West Center East SouthWest South SouthEast".split(" ") +GRAVITY_PARAMS = ["NorthWest","North","NorthEast","West","Center","East","SouthWest","South","SouthEast"] GRAVITY_DEFAULT = "center" -FORMAT = "jpg gif png".split(" ") -COMPOSE = [ "Over", "ATop", "Dst_Over", "Dst_In", "Dst_Out", "Multiply", +FORMAT_PARAMS = ["jpg", "gif", "png"] +COMPOSE_PARAMS = [ "Over", "ATop", "Dst_Over", "Dst_In", "Dst_Out", "Multiply", "Screen", "Divide", "Plus", "Difference", "Exclusion", "Lighten", "Darken", "Overlay", "Hard_Light", "Soft_Light", "Linear_Dodge", "Linear_Burn", "Color_Dodge", "Color_Burn" ] -DISPOSE = "None Previous Background".split(' '); +DISPOSE_PARAMS = ["None","Previous","Background"] +DISPOSE_DEFAULT = "None" class Generate(): def __init__(self, **kwargs): self.params = {} - self.tag = "im" self.now = utils.now() self.files_created = [] self.commands = []; @@ -94,13 +92,13 @@ class Generate(): "flip", "flop", "tile", "transparent", ]: self.params[k] = utils.bool_correct(utils.sanitize(kwargs[k])) - elif k == 'gravity' and self._test_enum(kwargs[k], GRAVITY): + elif k == 'gravity' and self._test_enum(kwargs[k], GRAVITY_PARAMS): self.params[k] = kwargs[k] - elif k == 'format' and self._test_enum(kwargs[k], FORMAT): + elif k == 'format' and self._test_enum(kwargs[k], FORMAT_PARAMS): self.params[k] = kwargs[k] - elif k == 'compose' and self._test_enum(kwargs[k], COMPOSE): + elif k == 'compose' and self._test_enum(kwargs[k], COMPOSE_PARAMS): self.params[k] = kwargs[k] - elif k == 'dispose' and self._test_enum(kwargs[k], DISPOSE): + elif k == 'dispose' and self._test_enum(kwargs[k], DISPOSE_PARAMS): self.params[k] = kwargs[k] elif k in [ "fuzz", "width", "height", "brightness", "contrast", "saturation", "rotate", "hue" ]: self.params[k] = int(kwargs[k]) @@ -109,34 +107,28 @@ class Generate(): else: self.params[k] = None; - self.params = utils.dotdict(self.params) - self.basename = self._get_filename(); - if not self.params.format: - self.params.format = DEFAULT_FINALFORMAT - if not self.params.dispose: - self.params.dispose = 'None'; - - self.filename = "{}.{}".format(self.basename, self.params.format) - #final filepath is stored in self.filepath + self.filename = "{}.{}".format(self.basename, self.params.get('format', DEFAULT_FINALFORMAT)) self.filepath = os.path.join(WORKING_DIR, self.filename) - print str(self.params); + + if self.params['bgfile']: + self.tag = self.params['compose'] + else: + self.tag = self.params['transparent'] or "im" def _make_tempname(self, s): return "PBTMP{}{}".format(self.now, s); - def _test_enum(self, k, arr): - if k in arr: - return True - else: - raise Exception("Bad Param: {}".format(k)) + def _test_enum(self, e, arr): + if e in arr: return True + raise Exception ("Bad value: {}".format(e)) def _get_filename(self): return "{}_{}_{}".format( self.tag, self.now, - self.params.username or "" + self.params.get('username',"") ); def _call_cmd(self, cmd): @@ -152,16 +144,14 @@ class Generate(): cmd = ["rm", "-f"] + self.files_created self._call_cmd(cmd) -#FIXME need to be more specific two functions below - def bin_composite (self, params, bottomfile, topfile, newfile): - cmd = [BIN_CONVERT] - cmd += [ bottomfile ] - cmd += [ "null:" ] - cmd += [ topfile ] - cmd += [ "-matte" ] - cmd += params - cmd += [ "-layers", "composite" ] - cmd += [ newfile ] + def _composite (self): + cmd = [ + BIN_CONVERT, self.params['bgfile'], + "null:", self.filepath, "-matte", + "-dispose", self.params.get('dispose', DISPOSE_DEFAULT), + "-gravity", self.params.get("gravity",GRAVITY_DEFAULT), + "-compose", self.params['compose'], "-layers", "composite", + self.filename ] self._call_cmd(cmd); def bin_convert (self, params, oldfile, newfile): @@ -170,60 +160,42 @@ class Generate(): cmd.append(newfile) self._call_cmd(cmd); - - def _build_cmd(self): + def _convert(self): cmd = [] - if self.params.rotate: cmd += ["-rotate", self.params.rotate ] - if self.params.flip: cmd += ["-flip"] - if self.params.flop: cmd += ["-flop"] - #FIXME add like a boss and make width == height when there's only one - #same thing in the other scripts - #also dotdict is bad, it's like javascript + if self.params['rotate']: cmd += ["-rotate", self.params['rotate'] ] + if self.params['flip']: cmd += ["-flip"] + if self.params['flop']: cmd += ["-flop"] if self.params['transparent']: - self.tag = "transparent" - if self.params.fuzz: - cmd += ["-fuzz", "{}%".format(self.params.fuzz) ] + if self.params['fuzz']: + cmd += ["-fuzz", "{}%".format(self.params['fuzz']) ] cmd += [ "-transparent", self.params.get('subtract', "white") ] - if self.params.width or self.params.height: - if self.params['nearest']: - if self.params.format == "gif": - cmd += [ "-coalesce","+map","-interpolate","Nearest","-interpolative-resize" ] - else: - cmd.append("-resize") - cmd.append("{}x{}".format(self.params.get('width',''), self.params.get('height',''))) - if self.params['black'] != "black" or self.params['white'] != 'white': - cmd += [ "+level-colors" , "{},{}".format(self.params.black, self.params.black) ] - if self.params.contrast: - cmd += [ '-contrast-stretch', self.params.contrast ] - if any( e in self.params.keys for e in ['brightness', 'saturation', 'hue' ]): - cmd += [ - "{},{},{}".format( - self.params.get('brightness', 100), - self.params.get('contrast', 100), - self.params.get('hue', 100) - ), - "-modulate" ] - if self.params.bgfile: - self.tag = self.params['compose'] - + if self.params['width'] or self.params['height']: + if self.params['nearest']: + if self.params['format'] == "gif": + cmd += [ "-coalesce","+map","-interpolate","Nearest","-interpolative-resize" ] + else: + cmd.append("-resize") + cmd.append("{}x{}".format(self.params.get('width',''), self.params.get('height',''))) + if self.params['black'] != "black" or self.params['white'] != 'white': + cmd += [ "+level-colors" , "{},{}".format(self.params['black'], self.params['black']) ] + if self.params['contrast']: cmd += [ '-contrast-stretch', self.params['contrast'] ] + if any( e in self.params.keys for e in ['brightness', 'saturation', 'hue' ]): + cmd += [ + "{},{},{}".format( + self.params.get('brightness', 100), + self.params.get('contrast', 100), + self.params.get('hue', 100) + ), + "-modulate" ] + cmd.append("-coalesce"); #why? #FIXME + self._call_cmd(cmd); + + def create(self): + if self._convert(); + if self.params['bgfile']: + self._composite() - cmd.append("-coalesce"); - compositeparams = ["-dispose", "None", "-gravity", self.params.get("gravity",GRAVITY_DEFAULT) ] - compositeparams.extend([ "-compose", self.params['compose'] ]) -# -# bin_convert (WORKING_DIR, cmd, oldfile, compositefile) -#then... -# bin_composite (compositeparams, bgfile, compositefile, newfile) -# -# insert_cmd(dir, oldfile, newfile, cmd, url, name, tag) -# -#else: -# bin_convert(WORKING_DIR, cmd, oldfile, newfile) -# insert_cmd(dir, oldfile, newfile, cmd, url, name, tag) -# ##remove(newfile) -# -#g.close() if __name__ == "__main__": TEST_PARAMS = { diff --git a/move_to_server b/move_to_server index 0cc890c..a5fb980 100644 --- a/move_to_server +++ b/move_to_server @@ -1,3 +1,8 @@ +# +# insert_cmd(dir, oldfile, newfile, cmd, url, name, tag) +# +# insert_cmd(dir, oldfile, newfile, cmd, url, name, tag) +# ## jsonp callback #if param['callback'] is not None: # url = (BASE_URL+dir+"/"+newfile).replace("'", "\\'") |
