diff options
| -rwxr-xr-x | pb/generate.py (renamed from generate.py) | 73 |
1 files changed, 32 insertions, 41 deletions
diff --git a/generate.py b/pb/generate.py index 1bc1655..bfac4b2 100755 --- a/generate.py +++ b/pb/generate.py @@ -8,7 +8,7 @@ import pb.lib.utils as utils #FIXME these guys can do stuff wider than 1000 LIKE_A_BOSS = "ryz pepper seamonkey JAMES".split(" ") DEFAULT_FINALFORMAT = "gif" -DB_TAG = "pb"; +DEFAULT_TAG = "im"; GRAVITY_PARAMS = ["NorthWest","North","NorthEast","West","Center","East","SouthWest","South","SouthEast"] GRAVITY_DEFAULT = "center" @@ -101,22 +101,19 @@ class Generate(): 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]) + self.params[k] = str(int(kwargs[k])) else: self.params[k] = utils.sanitize(kwargs[k]) - else: - self.params[k] = None; - + + if self.params.get('background'): + self.tag = self.params.get('compose') + else: + self.tag = self.params.get('transparent', DEFAULT_TAG) + self.basename = self._get_filename(); - self.filename = "{}.{}".format(self.basename, self.params.get('format', DEFAULT_FINALFORMAT)) self.filepath = os.path.join(WORKING_DIR, self.filename) - 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); @@ -146,56 +143,50 @@ class Generate(): def _composite (self): cmd = [ - BIN_CONVERT, self.params['bgfile'], + BIN_CONVERT, self.params['background']['path'], "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): - cmd = [BIN_CONVERT, oldfile] - cmd.extend(params) - cmd.append(newfile) + self.filepath ] self._call_cmd(cmd); 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"] - if self.params['transparent']: - if self.params['fuzz']: + cmd = [BIN_CONVERT, self.params['url']['path'] ] + if self.params.get('rotate'): cmd += ["-rotate", self.params['rotate'] ] + if self.params.get('flip'): cmd += ["-flip"] + if self.params.get('flop'): cmd += ["-flop"] + if self.params.get('transparent'): + if self.params.get('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": + if self.params.get('width') or self.params.get('height'): + if self.params.get('nearest'): + if self.params.get('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.append("{}x{}".format(self.params.get('width') or "", self.params.get('height') or "")) + if self.params.get('black') != "black" or self.params.get('white') != 'white': + cmd += [ "+level-colors" , "{},{}".format(self.params.get('black','black'), self.params.get('white', 'white')) ] + if self.params.get('contrast'): cmd += [ '-contrast-stretch', self.params['contrast'] ] + if any( e in self.params.keys() for e in ['brightness', 'saturation', 'hue' ]): cmd += [ - "{},{},{}".format( + "-modulate", "{},{},{}".format( self.params.get('brightness', 100), self.params.get('contrast', 100), self.params.get('hue', 100) - ), - "-modulate" ] + )] cmd.append("-coalesce"); #why? #FIXME + cmd += [ self.filepath ]; self._call_cmd(cmd); def create(self): - if self._convert(); - if self.params['bgfile']: + self._convert() + if self.params.get('background'): self._composite() + self._cleanup(); -##remove(newfile) if __name__ == "__main__": TEST_PARAMS = { @@ -203,7 +194,7 @@ if __name__ == "__main__": # 'height': None, 'compose': 'Soft_Light', 'coalesce': 'true', - 'dispose': 'true', + 'dispose': 'None', 'gravity': 'Center', 'width': '200', 'black': 'black', @@ -227,4 +218,4 @@ if __name__ == "__main__": 'fuzz': '5' } g = Generate(**TEST_PARAMS); - + g.create() |
