How to convert HTML to image with PHP [duplicate] - php

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Screenshot of current page using PHP
How to convert HTML to image with PHP , have idea!!!

If you have Python, PyQt4 and Webkit installed on your server, you can use Webkit2PNG to do this: it downloads the page, fires up the Webkit rendering engine, and takes a snapshot.
Note that this could be resource-intensive; also, rendering can differ in various browsers (and in IE).

In order to get an image of a web page, you need software that can render a web page (that is, lay out elements, apply styles, and so on). Such software is typically called a "browser".
It's possible to automate a browser from PHP, using COM (like in sAc's answer) on windows, for example.

Related

Create an image from an url using PHP GD [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to save webpage as a image file using PHP?
I would like to create an image on the server using a url string that is given.
I want a screen shot of a website to be created.
Is it possible with PHP GD , if so how ?
Thanks
You need something like PhantomJS to do it. This can be called from PHP.
Pretty sure GD can't handle this by itself. You'd need an HTML renderer too.
As far as I know, there is no existing PHP-Lib, which can do this. PHP-GD has to do with graphics, but you cant do this with it. Even if: What will happen, if the Site uses Javascript to enable certain important parts of a site? Or even images or other resources, that require long running requests? Or consider sites using flash... There are some tools for linux to take screenshots in batch - configurable with timer etc.

Html to jpeg as thumbnail [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Website screenshots using PHP
Can someone tell me how to take a thumbnail off of a web page using php or js without any 'API' support? Otherwise convert HTML to PS and PS to jpeg is also possible.
Thank you.
Try Phantom JS. It can be used to render HTML from the commandline, using various output formats. Creating a thumbnail can be done by setting the zoom factor.
WKHtmlToImage is able to render a webpage using webkit engine. You will have to launch an executable on server-side though.

how can i take a screen shot and save it in PHP [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Website screenshots using PHP
how can i take a screen shot and save it in PHP? I wana take a screen shot a users screen and save it to user's machine when he/she clicks on save button. Is there any way to do this??
You can't do this in PHP.
You could do this using HTML5/Javascript, something like HTML2Canvas does.
Your problem with that would be compatibility with older browsers. So using this would depend on who the website is aimed at.
You have to understand one thing that PHP is a server side script and nothing to do with real time browser needs. You may try JavaScript with some library like jQuery to capture the screenshot. Then you may pass that image via AJAX and there, you can definitely use PHP to save the image into your server directory.
this stackoverflow question may help you.

How can I get the thumbnail of a website? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Website screenshots using PHP
I want to create a script that will show the thumbnail of a site (let's say 400*300px ). I don't want sites like www.bitpixels.com .
So the answear could come in 2 ways:
1) You explain how could I take the screenshot of a website (using only PHP,ajax, etc,... no .NET or other stuff like that :D )
2) You know a website that offers this type of service for free and there's no limitation in the number of thumbs you can get, or their size.
You may want to try wkhtmltopdf (webkit-based html to pdf conversion), it also contains wkhtmltoimage, a version of it that outputs images. It's open source and if you have any sort of dedicated machine you should be able to use it. Otherwise I am not sure. Since it is webkit based it should provide you with a decent rendering of the page too.
Another great tool for this is PhantomJS

Converting HTML to PDF using PHP? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Convert HTML + CSS to PDF with PHP?
Is it possible to convert a HTML page to PDF using PHP, and if so, how can it be done?
Specifically, the page is an invoice generated dynamically. So I would like it loaded using:
http://example.com/invoices/3333
And the HTML output would have to be converted to PDF.
Any good libraries that do this will be fine.
If you wish to create a pdf from php, pdflib will help you (as some others suggested).
Else, if you want to convert an HTML page to PDF via PHP, you'll find a little trouble outta here.. For 3 years I've been trying to do it as best as I can.
So, the options I know are:
DOMPDF : php class that wraps the html and builds the pdf. Works good, customizable (if you know php), based on pdflib, if I remember right it takes even some CSS. Bad news: slow when the html is big or complex.
HTML2PS: same as DOMPDF, but this one converts first to a .ps (ghostscript) file, then, to whatever format you need (pdf, jpg, png). For me is little better than dompdf, but has the same speed problem.. but, better compatibility with CSS.
Those two are php classes, but if you can install some software on the server, and access it throught passthru() or system(), give a look to these too:
wkhtmltopdf: based on webkit (safari's wrapper), is really fast and powerful.. seems like this is the best one (atm) for converting html pages to pdf on the fly; taking only 2 seconds for a 3 page xHTML document with CSS2. It is a recent project, anyway, the google.code page is often updated.
htmldoc : This one is a tank, it never really stops/crashes.. the project looks dead since 2007, but anyway if you don't need CSS compatibility this can be nice for you.

Categories