]> git.lyx.org Git - lyx.git/blob - lib/scripts/pic2ascii.py
update to the aa class
[lyx.git] / lib / scripts / pic2ascii.py
1 #!/usr/bin/python
2 # This script converts a raster format picture into an ascii representation
3 # with the suffix .asc
4
5 import sys
6 import os
7 import os.path
8 import string
9
10 pid = os.fork()
11 if pid == 0:
12         os.execvp("convert", ["convert", sys.argv[1], "temporary_filename_that_is_long.gif"])
13         print "Could not run convert"
14         os.exit(1)
15 os.wait()
16
17 os.system("identify temporary_filename_that_is_long.gif > temp.dim")
18
19 fp = open("temp.dim", "r")
20 line = fp.readline()
21 lines = string.split(line,' ')
22 dims = string.split(lines[1],'x')
23 xsize = float(dims[0])
24 ysize = float(string.split(dims[1],'+')[0])
25
26 aspect_ratio = xsize / ysize
27
28 if len(sys.argv) > 2:
29         resulting_x = int(sys.argv[2])
30 else:
31         resulting_x = 40
32 resulting_y = int(resulting_x / aspect_ratio)
33
34 os.system("echo s | gifscii temporary_filename_that_is_long.gif %d %d" % (resulting_x, resulting_y))
35
36 os.system("tail +3 temporary_filename_that_is_long.asc > temporary_filename_that_is_long2.asc")
37
38 pid = os.fork()
39 if pid == 0:
40         os.execvp("mv", ["mv", "temporary_filename_that_is_long2.asc", os.path.splitext(sys.argv[1])[0] + ".asc"])
41         print "Could not rename file"
42         os.exit(1)
43 os.wait(pid)
44
45 os.system("rm temporary_filename_that_is_long.gif temporary_filename_that_is_long.asc")
46