1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#!/Python27/python.exe
#/usr/bin/python
import downloader
import filenamer
import inventnamer
import fieldstorager
print "Content-Type: text/html"
print
print ""
nametag = "imDither"
MAIN_DIRECTORY = ""
#BIN_CONVERT = "/usr/bin/convert"
#BIN_IDENTIFY = "/usr/bin/identify"
#BIN_COMPOSITE = "/usr/bin/composite"
BIN_CONVERT = "convert"
BIN_IDENTIFY = "identify"
BIN_COMPOSITE = "composite"
PARAM_LIST = "theurl, thedither, username, format"
form = cgi.FieldStorage()
newvalues = fieldstorager.fieldstorage(PARAM_LIST, form)
thekeys = PARAM_LIST.split()
for key in thekeys:
globals()[key] = newvalues[key]
if username == None:
username = ""
format = format
if format == None:
format = "png"
class Dither():
def file_size (self, file)
return os.stat(file)[6]
def identify(self, thefile):
ident = Popen([BIN_IDENTIFY, thefile], stdout=PIPE).communicate()[0]
partz = ident.split(" ")
self.dimensions = partz[2].split("x")
def makeCanvas(self, dimensions, thefile):
os.system(BIN_CONVERT+" "-size "+self.dimensions[0]+"x"+self.dimensions[1]+" canvas:transparent"+thefile)
def makeMask(self, themask, thedither, thebackground):
os.system(BIN_CONVERT+" -tile "+thedither+" "+thebackground+" "+themask)
os.system("rm "+thebackground)
def fuseMask(self, themask, theimage):
os.system(BIN_CONVERT+" "+themask+" null: "+theimage+" -matte -compose DstIn -layers composite "+theimage)
os.system("rm "+themask)
def init(self, theurl, thedither, username):
self.mainfile = filenamer.filename(theurl, "imDither", username)
filepaths = hexdirer.hexdir
self.privatepath = filepaths[0]
self.publicpath = filepaths[1]
downloader.download(theurl, self.mainfile, self.privatepath)
self.canvasfile = inventnamer.inventname("png", "canvasfile")
self.dimensions = self.identify(self.mainfile)
self.makeCanvas(self.dimensions, self.canvasfile)
self.theMask = inventnamer.inventname("png", "maskfile")
self.makeMask(self.theMask, thedither, self.canvasfile)
self.fuseMask(self.theMask, self.mainfile)
#self.mainfile = self.mainfile.replace(, do something with s3)
print self.mainfile
print self.file_size(self.mainfile)
print 'width: '+self.dimensions[0]+'px'
print 'height: '+self.dimensions[1]+'px'
daddy = Dither(theurl, thedither, username)
|