Sto usando wkhtmltoimage.
È uno strumento rapido da riga di comando che usa la libreria webkit per rendere qualsiasi sito web. Ci sono due versioni una per generare pdf e una per generare immagini.
wkhtmltoimage funziona con Windows, Linux e Mac.
http://code.google.com/p/wkhtmltopdf/
/wkhtmltoimage-i386 -H Name: wkhtmltoimage 0.10.0 rc2 Synopsis: wkhtmltoimage [OPTIONS]... Description: Converts an HTML page into an image, General Options: --allow Allow the file or files from the specified folder to be loaded (repeatable) --checkbox-checked-svg Use this SVG file when rendering checked checkboxes --checkbox-svg Use this SVG file when rendering unchecked checkboxes --cookie Set an additional cookie (repeatable) --cookie-jar Read and write cookies from and to the supplied cookie jar file --crop-h Set height for croping --crop-w Set width for croping --crop-x Set x coordinate for croping --crop-y Set y coordinate for croping --custom-header Set an additional HTTP header (repeatable) --custom-header-propagation Add HTTP headers specified by --custom-header for each resource request. --no-custom-header-propagation Do not add HTTP headers specified by --custom-header for each resource request. --debug-javascript Show javascript debugging output --no-debug-javascript Do not show javascript debugging output (default) --encoding Set the default text encoding, for input -H, --extended-help Display more extensive help, detailing less common command switches -f, --format Output file format (default is jpg) --height Set screen height (default is calculated from page content) (default 0) -h, --help Display help --htmldoc Output program html help --images Do load or print images (default) --no-images Do not load or print images -n, --disable-javascript Do not allow web pages to run javascript --enable-javascript Do allow web pages to run javascript (default) --javascript-delay Wait some milliseconds for javascript finish (default 200) --load-error-handling Specify how to handle pages that fail to load: abort, ignore or skip (default abort) --disable-local-file-access Do not allowed conversion of a local file to read in other local files, unless explecitily allowed with --allow --enable-local-file-access Allowed conversion of a local file to read in other local files. (default) --manpage Output program man page --minimum-font-size Minimum font size --password HTTP Authentication password --disable-plugins Disable installed plugins (default) --enable-plugins Enable installed plugins (plugins will likely not work) --post Add an additional post field (repeatable) --post-file Post an additional file (repeatable) -p, --proxy Use a proxy --quality Output image quality (between 0 and 100) (default 94) --radiobutton-checked-svg Use this SVG file when rendering checked radiobuttons --radiobutton-svg Use this SVG file when rendering unchecked radiobuttons --readme Output program readme --run-script Run this additional javascript after the page is done loading (repeatable) -0, --disable-smart-width Use the specified width even if it is not large enough for the content --stop-slow-scripts Stop slow running javascripts (default) --no-stop-slow-scripts Do not Stop slow running javascripts (default) --transparent Make the background transparent in pngs --use-xserver Use the X server (some plugins and other stuff might not work without X11) --user-style-sheet Specify a user style sheet, to load with every page --username HTTP Authentication username -V, --version Output version information an exit --width Set screen width (default is 1024) (default 1024) --window-status Wait until window.status is equal to this string before rendering page --zoom Use this zoom factor (default 1) Specifying A Proxy: By default proxy information will be read from the environment variables: proxy, all_proxy and http_proxy, proxy options can also by specified with the -p switch := "http://" | "socks5://" := (":" )? "@" := "None" | ? ? (":" )? Here are some examples (In case you are unfamiliar with the BNF): http://user:[email protected] :8080 socks5://myproxyserver None Contact: If you experience bugs or want to request new features please visit , if you have any problems or comments please feel free to contact me:
demo:
./wkhtmltoimage-i386 "http://stackoverflow.com/questions/11907986/convert-html-file-to-image/11908055#11908055" demo.png
C’è anche PhantomJS (vedi http://phantomjs.org ). Lo uso in un motore di ricerca scritto in PHP per generare le miniature del sito Web. Come wkhtmltoimage, è un programma a riga di comando basato su WebKit e può generare immagini e PDF. Ma poiché è un browser completo, utilizza JavaScript per eseguire l’elaborazione.
MODIFICA: vedi https://github.com/ariya/phantomjs/wiki/Screen-Capture per un esempio concreto di rendering delle immagini.
Se hai bisogno di un programma a riga di comando, prova IECapt . Usa il motore di rendering di Internet Explorer. C’è anche un programma multipiattaforma chiamato CutyCapt , che non ho provato. Una nota al parametro file di IECapt: ha funzionato solo specificando il percorso completo del file. Sembra che i percorsi relativi non siano riconosciuti. Le --file:"C:\....."
nel percorso sono permesse come: --file:"C:\....."