Incomplete Google App Engine Documentation on Conversion API

后端 未结 1 495
小鲜肉
小鲜肉 2021-01-23 11:45

I am trying to convert a HTML string into a .PNG file. Thanks to Nick Johnson who pointed me to GAE Conversion API see previous post Here.

I use the GAE Conversion API

相关标签:
1条回答
  • 2021-01-23 12:10

    The documentation says that the name of the asset should match the src attribute of the img tag.

    Here is a python code I tried in the interactive console, and it actually produced the two images

    from google.appengine.api import urlfetch
    from google.appengine.api import conversion
    
    url = "http://a0.twimg.com/profile_images/77186109/favicon_reasonably_small.png"
    asset = conversion.Asset("text/html", '<b>some data</b><br/><img src="a.png"/><img src="%s"/><br/>Foo' % url, "test.html")
    conversion_obj = conversion.Conversion(asset, "image/png")
    
    img_response = urlfetch.fetch(url)
    image1 = conversion.Asset('image/png', img_response.content, "a.png")
    image2 = conversion.Asset('image/png', img_response.content, url)
    conversion_obj.add_asset(image1)
    conversion_obj.add_asset(image2)
    
    result = conversion.convert(conversion_obj)
    print result.error_text
    
    print repr(result.assets[0].data)
    
    0 讨论(0)
提交回复
热议问题