Is it possible to invoke PhantomJS through the bro

2019-09-15 07:36发布

问题:

I'm trying to generate server-side images of a portion of my DOM, and then serve those images up to users from my server once they're created.

I'm curious as to the implementation possibilities of PhantomJS, as I don't entirely understand its purpose beyond exploring and testing. I get that it is a self-contained binary, and I've got it running basic apps like in their tutorials. But is there a way to do something along the lines of the following?

<html>
    <body>
        <h1>This is a test.</h1>
        <button>Rasterize!</button>
    </body>
    <script>
        $('button').click(function() {
            // invoke PhantomJS here to generate PNG of this page
        });
    </script>
<html>

Specifically, I'm looking at doing something along the lines of:

phantomjs rasterize.js https://localhost:9999/test.html test.png

Someone, please, school me!