Ejemplo n.º 1
0
 def make_images(q):
   eq = None
   while True:
     try:
       (eq, hash) = q.get(timeout=1)
       # create and save image
       dir = MEDIA_ROOT + "/formulas/"
       math2png([eq], dir, prefix=hash)
     except Empty:
       return
Ejemplo n.º 2
0
  def __replace(m):
    formula = m.group(1)

    # hash the formula to make a unique url
    h = hashlib.sha1()
    h.update(formula)

    # use hexdigest because digest produces possibly unsafe characters 
    hash = h.hexdigest() 

    # create and save image
    dir = MEDIA_ROOT + "/formulas/"
    math2png([formula], dir, prefix=hash)
                         
    return '<img src="%sformulas/%s1.png" alt="%s" />' \
        % (MEDIA_URL, hash, formula)