0

Can I get some sample code in PHP for converting an html table to image form(.gif,.jpg or any format)? I am using XAMPP on Windows.
Yes, the table is coming from the database.

1
  • something tells me this isnt the best solution to whatever your problem is Commented Apr 6, 2009 at 14:26

4 Answers 4

3

The best way is to convert first in a .ps, then jpg, pdf, or whatelse you need. I can suggest you 2 links: html2ps

wkhtmltopdf

Tested both, and both works perfectly... html2ps is little slow (~30 sec for a 3 pages pdf, dunno about jpg) but more customizable. Give them a look

Sign up to request clarification or add additional context in comments.

1 Comment

oh, i forget a thick - if you use windows, you can use wkhtmltopdf for win wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.8.0.exe and use it by command line, somethings like wkhtmltopdf-0.8.0.exe 127.0.0.1/yourpage.php outputfile.pdf Obviusly, you can run it even under php (passthru())
1

you like to have an screenshot from an html-table / html-code? Thats not possible with php only. You need a webbrowser or an html-renderer and a program do make an screenshot.

look at http://www.thumbshots.org/ (onlineservice)

or http://www.intellitamper.com/webswoon/ (python tool.)

Comments

1

At first glance, that's quite a tall order. Here are some pointers:

  • You'll probably want to get cosy with the GD library

Where is this table coming from? If it's coming from your database originally, this would be easier to work with. Otherwise...

  • You'll need to get the remote page (I recommend curl)
  • Then you'll need to extract the table data

The complexity of the second step really depends on how similar each page and table is going to be. Regex is probably going to be useful though.

Hope this helps,

Tom

Comments

0

As DrFuture mentions, using php only is probably not the best way to go to convert a table into an image. I modified http://www.zubrag.com/scripts/website-thumbnail-generator.php to get it to convert my html into an image (put the html on another webpage and pass that url to the script). I would suggest going with the 'screenshot' route instead of GDI and other drawing tools.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.