import re
import os
import shutil

filename = "orthocenter"
fileasy = "asy-sources/" + filename + ".asy"
filepng = "diagrams/" + filename + ".png"
filetxt = "/tmp/" + filename + ".txt"
filenewasy = "/tmp/" + filename + "_temp.asy"
filejson = "diagrams/" + filename + ".json"

with open(fileasy, 'r') as r:
	pts_list = []
	tuple_list = []
	shutil.copyfile(fileasy, filenewasy);
	for line in r:
		line = line.strip()
		if line.startswith('Source:'):
			source = line.strip('Source: ')
		elif line.startswith('Points:'):
			line = line.strip('Points: ')
			pts_list = line.split()
		elif line.startswith('Tuple:'):
			line = line.strip('Tuple: ').strip()
			tuple_list.append(line.split())

with open(filenewasy, 'a') as w:
	for pt in pts_list:
		print >>w, "write(\"Point: %s,\" + (string) %s);" %(pt, pt)
	print >>w, "write(\"min \" + (string) min(currentpicture, user=true));"
	print >>w, "write(\"max \" + (string) max(currentpicture, user=true));"
command = "asy -f png -o %s %s > %s" %(filepng, filenewasy, filetxt)
print command
os.system(command)

#reading txt file from asymptote
pts_coor = []
min_list = []
max_list = []
r = open(filetxt, "r")
for line in r:
	if line.startswith('Point: '):
		line = line.strip('Point: ').strip()
		pts_coor.append(line.split(","))
	elif line.startswith('min '):
		line = line.strip('min ').strip()
		min_list = line.split(",")
	elif line.startswith('max '):
		line = line.strip('max ').strip()
		max_list = line.split(",")	

#writing json file
print pts_coor
g = open(filejson, 'w')
g.write('{\n')
g.write('"points" : [\n')
print >>g, ',\n'.join([ '["%s", %s, %s]' %(pt[0], pt[1][1:], pt[2][:-1]) for pt in pts_coor ])
print >>g, '],'

print >>g, '"min" : [%s,%s],' %(min_list[0][1:], min_list[1][:-1])
print >>g, '"max" : [%s,%s],' %(max_list[0][1:], max_list[1][:-1])

print >>g, '"tuples" : ['
print >>g, ',\n'.join([ '['+','.join(['"%s"' %p for p in ls])+']' for ls in tuple_list ])
print >>g, '],'

print >>g, '"source" : "%s",' %(source)
print >>g, '"filename" : "%s"' %(filename)
print >>g, '}'

@@ -818,16 +818,17 @@
 write(%5C%22
+u
 min %5C%22 +
@@ -870,16 +870,35 @@
 true));%22
+ # User coordinates
 %0A%09print 
@@ -911,16 +911,17 @@
 write(%5C%22
+u
 max %5C%22 +
@@ -964,16 +964,183 @@
 rue));%22%0A
+%09print %3E%3Ew, %22write(%5C%22pmin %5C%22 + (string) min(currentpicture, user=false));%22 # PS coordinates%0A%09print %3E%3Ew, %22write(%5C%22pmax %5C%22 + (string) max(currentpicture, user=false));%22%0A
 command 
@@ -1476,16 +1476,17 @@
 tswith('
+u
 min '):%0A
@@ -1483,28 +1483,32 @@
 'umin '):%0A%09%09
-line
+min_list
  = line.stri
@@ -1510,16 +1510,17 @@
 .strip('
+u
 min ').s
@@ -1525,34 +1525,100 @@
 .strip()
-%0A%09%09min_list = line
+.split(%22,%22)%0A%09elif line.startswith('umax '):%0A%09%09max_list = line.strip('umax ').strip()
 .split(%22
@@ -1648,22 +1648,28 @@
 th('
-max
+pmin
  '):%0A%09%09
-line
+pmin_list
  = l
@@ -1679,19 +1679,20 @@
 .strip('
-max
+pmin
  ').stri
@@ -1698,38 +1698,242 @@
 ip()
-%0A%09%09max_list = line.split(%22,%22)%09
+.split(%22,%22)%0A%09%09pxmin = float(pmin_list%5B0%5D%5B1:%5D)%0A%09%09pymin = float(pmin_list%5B1%5D%5B:-1%5D)%0A%09elif line.startswith('pmax '):%0A%09%09pmax_list = line.strip('pmax ').strip().split(%22,%22)%0A%09%09pxmax = float(pmax_list%5B0%5D%5B1:%5D)%0A%09%09pymax = float(pmax_list%5B1%5D%5B:-1%5D)
 %0A%0A#w
@@ -2478,16 +2478,17 @@
 %22 : %22%25s%22
+,
 ' %25(file
@@ -2493,16 +2493,104 @@
 lename)%0A
+print %3E%3Eg, '%22width%22 : %22%25f%22,' %25(pxmax-pxmin)%0Aprint %3E%3Eg, '%22height%22 : %22%25f%22' %25(pymax-pymin)%0A
 print %3E%3E

Add height/width into append.py