diff options
| author | pepperpepperpepper <pepper@scannerjammer.com> | 2015-11-18 10:08:55 -0800 |
|---|---|---|
| committer | pepperpepperpepper <pepper@scannerjammer.com> | 2015-11-18 10:08:55 -0800 |
| commit | 67033f5c20c9c1c6653cdb3e66a74539d634ec64 (patch) | |
| tree | e3981e3d035d63995a78b0d2d455302f6875fb88 /share/frontend/imdither/makeDither.py | |
| parent | 348494657b7366263de6baf09ddfc6a528fac594 (diff) | |
cleanup continued
Diffstat (limited to 'share/frontend/imdither/makeDither.py')
| -rwxr-xr-x | share/frontend/imdither/makeDither.py | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/share/frontend/imdither/makeDither.py b/share/frontend/imdither/makeDither.py deleted file mode 100755 index 57775fb..0000000 --- a/share/frontend/imdither/makeDither.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/python2.7 - -import cgi -import pbutils -from os import getpid, path -from subprocess import call - -MAIN_DIRECTORY = "" -BIN_CONVERT = "convert" -BIN_IDENTIFY = "identify" -BIN_COMPOSITE = "composite" - -class Dither: - def __init__(self, - input_file_path, - dither_file="1.png", - username="", - ): - - self.nametag = "imDither"; - if username: - self.username = username - else: - self.username = ""; - - self.pid = str(getpid()) - self.dither_file = dither_file; - self.original_file = input_file_path; - self.MAX_NAME_LENGTH = 10; - - self.image_format = self.original_file.split(".")[-1] - try: - self.dimensions = pbutils.image_dimensions_and_test(self.original_file); - except Exception as E: - pbutils.error("Corrupt image") - self.canvas_file = self.pid+"blank_canvas.png"; - self.makeCanvas(); - self.mask_file = self.pid+"mask_file"+"."+self.image_format; - self.makeMask(); - self.result_file = self.makeResultFilename(); - self.fuseMask(); - - def makeResultFilename(self): - file_base, extension = path.splitext(self.original_file) - if len(file_base) > self.MAX_NAME_LENGTH: - file_base = file_base[0:self.MAX_NAME_LENGTH] - return "%s_%s_%s%s%s" % (file_base, self.username, self.nametag, pbutils.now(), extension) - - #first step - def makeCanvas(self): - call([BIN_CONVERT,"-size",self.dimensions[0]+"x"+self.dimensions[1],"canvas:transparent", self.canvas_file]) - - #second step use the Canvas as a background - def makeMask(self): - #tile the dither pattern on the canvas - call([BIN_COMPOSITE,"-tile", self.dither_file, self.canvas_file, self.mask_file]) - - #fuse the tiled file to create a mask - #convert thebg.gif -compose Dst_In null: thefile.gif -matte -layers composite new.gif - call([BIN_CONVERT, self.mask_file, "-compose", "Dst_In", "null:", self.original_file, "-matte", "-layers", "composite", self.mask_file]) - - #cleanup - call(["rm", self.canvas_file]) - - #third step - def fuseMask(self, fuse_mode="Pin_Light"): - call([BIN_CONVERT, self.mask_file, "null:", self.original_file, "-matte", "-compose", fuse_mode, "-layers", "composite", self.result_file]) - call(["rm", self.mask_file]) - - -if __name__ == "__main__": - dither = Dither("./test.gif"); |
