summaryrefslogtreecommitdiff
path: root/lib/Pb/Generate.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Pb/Generate.py')
-rwxr-xr-xlib/Pb/Generate.py140
1 files changed, 0 insertions, 140 deletions
diff --git a/lib/Pb/Generate.py b/lib/Pb/Generate.py
deleted file mode 100755
index e631002..0000000
--- a/lib/Pb/Generate.py
+++ /dev/null
@@ -1,140 +0,0 @@
-#!/usr/bin/python2.7
-import sys
-import os
-from config import *
-from Pb import Pb
-_default_tag = "im"
-
-_gravity_params = ["NorthWest","North","NorthEast","West","Center","East","SouthWest","South","SouthEast"]
-_gravity_default = "Center"
-_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_params = ["None","Previous","Background"]
-_dispose_default = "None"
-class PbGenerate(Pb):
- example_params = {
-#{{{ example params
- 'nearest': 'true',
- # 'height': None,
- 'compose': 'Soft_Light',
- 'coalesce': 'true',
- 'dispose': 'None',
- 'gravity': 'Center',
- 'width': '200',
- 'black': 'black',
- 'tile': 'true',
- 'white': 'white',
- 'contrast': '100',
- 'hue': '90',
- 'saturation': '100',
- 'merge_early': 'true',
- 'format': 'gif',
- 'background': 'http://i.asdf.us/im/bc/new_1430440747.gif',
- 'subtract': '#EE7AE9',
- 'transparent': 'true',
- # 'rotate': None,
- 'name': 'yo',
- # 'brightness': None,
- 'url': 'http://asdf.us/im/new.gif',
- 'flop': 'true',
- 'flip': 'false',
- 'callback': 'jsonp1430442384162',
- 'fuzz': '5'
-#}}}
- }
- def __init__(self, **kwargs):
- super(PbGenerate,self).__init__(**kwargs);
- _definitions = {
- #IMAGES
- "url": { 'type': "img_url" },
- "background": { 'type': "img_url" },
-
- #BOOLS
- "coalesce": { 'type': "bool" },
- "nearest": { 'type': "bool" },
- "merge_early": { 'type': "bool" },
- "flip": { 'type': "bool" },
- "flop": { 'type': "bool" },
- "tile": { 'type': "bool" },
- "transparent": { 'type': "bool" },
-
- #COLORS
- "black": { 'type': "color", 'default': 'black' },
- "white": { 'type': "color", 'default': 'white' },
- "subtract": { 'type': "color" },
-
- #INTS
- "fuzz": { 'type': "int" },
- "width": { 'type': "int" },
- "height": { 'type': "int" },
- "brightness": { 'type': "int" },
- "contrast": { 'type': "int" },
- "saturation": { 'type': "int" },
- "rotate": { 'type': "int" },
- "hue": { 'type': "int" },
-
- #ENUMS
- "compose": { 'type': "enum", 'enum_values': _compose_params, 'default': "Atop" },
- "gravity": { 'type': "enum", 'enum_values': _gravity_params, 'default': _gravity_default },
- "dispose": { 'type': "enum", 'enum_values': _dispose_params, 'default': "None" },
- "format": { 'type': "enum", 'enum_values': OUTPUT_IMAGE_TYPES, 'default': DEFAULT_FINALFORMAT },
-
- #STRINGS
- "username": { 'type': "string" },
- "callback": { 'type': "string" },
- }
- self.tag = _default_tag
- self.params.definitions_import(_definitions, kwargs, classname=self.__class__.__name__);
- if self.params.background: self.tag = self.params.compose
- if self.params.transparent: self.tag = self.params.transparent
-
- self.filename, self.filepath = self._filename_filepath_create(url=self.params.url['url'], extension=self.params.format)
-
- self._db_url_param = str(self.params.url['url'])
-
- def _composite (self):
- cmd = [
- BIN_CONVERT, self.params.background['path'],
- "null:", self.filepath, "-matte",
- "-dispose", self.params.dispose,
- "-gravity", self.params.gravity,
- "-compose", self.params.compose, "-layers", "composite",
- self.filepath ]
- self._call_cmd(cmd);
-
- def _convert(self):
- cmd = [BIN_CONVERT, self.params.url['path'] ]
- 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 += ["-fuzz", "{}%".format(self.params.fuzz) ]
- cmd += [ "-transparent", self.params.subtract ]
- if self.params.width or self.params.height:
- if self.params.nearest and self.params.format == "gif":
- cmd += [ "-coalesce","+map","-interpolate","Nearest","-interpolative-resize" ]
- else:
- cmd.append("-resize")
- cmd += [ "{}x{}".format(self.params.width or "", self.params.height or "") ]
- if self.params.black != "black" or self.params.white != 'white':
- cmd += [ "+level-colors" , "{},{}".format(self.params.black, self.params.white) ]
- if self.params.contrast: cmd += [ '-contrast-stretch', self.params.contrast ]
- if self.params.brightness or self.params.saturation or self.params.hue:
- cmd += [
- "-modulate", "{},{},{}".format(
- (self.params.brightness or 100),
- (self.params.contrast or 100),
- (self.params.hue or 100)
- )]
- cmd.append("-coalesce"); #why? #FIXME
- cmd += [ self.filepath ];
- self._call_cmd(cmd);
-
- def create(self):
- self._convert()
- if self.params.background:
- self._composite()
- super(PbGenerate, self).create()