summarylogtreecommitdiffstats
path: root/stl.thumbnailer.py
blob: 4ba23f3a54503d8239d9dbb651445c8bddd4209b (plain)
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
#!/usr/bin/python2



import os
import sys
import time
import hashlib


fin = ""
fout = ""
size = ""

def main( ):
	
	m = hashlib.md5()
	m.update(fin)
	

	ff = "/tmp/stl_to_png_%s.scad" % m.hexdigest()

	f = open(ff,"w")
	f.write("color([__color__]) import(\"%s\");"%fin)
	f.close()


	cmd = "openscad -o %s.png --imgsize=%s,%s %s 2> /dev/null; mv %s.png %s" % (fout, size,size,ff,fout,fout)
	os.system(cmd)

	os.remove(ff)

	sys.exit(0)
		

if __name__ == '__main__':

	f = open("/tmp/stl_to_png_tmp.log","w")
	f.write("%i %s"%(len(sys.argv),sys.argv))
	f.close()	

	if len(sys.argv) <> 4:
		print "add args [in file] [out file] [size]"
		sys.exit(0)
	else:
		fin = sys.argv[1]
		fout = sys.argv[2]
		size = sys.argv[3]

	main( )