[pyar] HTML a PNG/JPG lo que se les cante

nachopro tranceway en gmail.com
Mie Sep 11 15:34:13 ART 2013


Che, no se tomen ni 5 meses ni se quemen las pestañas codeando para afuera.

Este código lo tengo corriendo en mi Django en una instancia micro de
aws, si googlean PHANTOMJS y RASTERIZE van a ser muy felices.

https://github.com/ariya/phantomjs/wiki/Screen-Capture

def capture_screenshot(article):
    try:
        fd, filename = tempfile.mkstemp(suffix=".png")
        os.fdopen(fd, "w").close() # it's only to be sure it doesn't exist
        call([
            settings.PHANTOMJS_BINARY,
            settings.RASTERIZE_PATH,
            article.url,
            filename
        ])
        article.screenshot.save("news/%d.png" % (article.id,),
ContentFile(file(filename).read()))
        os.unlink(filename)
    except:
        logger.error(
            "Unable to capture screenshot",
            exc_info=True,
            extra={
                "article": article,
            }
        )




-- 
ignacio benedetti a.k.a. nachopro
mailto:tranceway en gmail.com
http://blog.nachopro.com.ar/


More information about the pyar mailing list