Convert html table to an image using php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yoda69
Forum Newbie
Posts: 16
Joined: Wed Jun 20, 2007 10:21 am

Convert html table to an image using php

Post by yoda69 »

Hi,

I have a table (100 x 100 - coming out of a database) with every cell filled with a different color. Is there a way using a php function so the client actually see the table as an image?
Is there a way to make a snapshot of the table using a script or something like that?

Thanks,
ell0bo
Forum Commoner
Posts: 79
Joined: Wed Aug 13, 2008 4:15 pm

Re: Convert html table to an image using php

Post by ell0bo »

You have two options, you either use an HTML table, or a series of spans floated left.

In either case, you just makes the pixel data up with a HTML element, and simply format it with 'width: 1px; line-height: 1px; font-size: 1px; background-color: $something' . Now if you're going with the floating solution, you need to add 'display: block' to the spans. When you're using a table, make sure to set the cellpadding and cellspacing to 0, so that you don't have the gap between pixels.
yoda69
Forum Newbie
Posts: 16
Joined: Wed Jun 20, 2007 10:21 am

Re: Convert html table to an image using php

Post by yoda69 »

Thanks for the suggestion. However, if I want to create a really large table like 10000 cells, the web page will become too large and then I would like to first let the client see a snapshot.
then the client can click on an link which will show a smaller area of the table and allow him to choose cell. Therefore, I fear that I have to find some solution of creating a snapshot. Any suggestions?
ell0bo
Forum Commoner
Posts: 79
Joined: Wed Aug 13, 2008 4:15 pm

Re: Convert html table to an image using php

Post by ell0bo »

So... let me make sure i have this strait. You have a 1000 x 1000 px image saved into your database. You then are trying to output it as a 100 x 100 image? Alright, why is the images stored like that in the database. It sounds like a bad design personally.

However, if you're actually trying to do that, you're going to have to do image manipulation. That's a little beyond my realm of expertise. You'd have to take a sample of every 10 px, and then factor in the pixels you're removing to calculate what the color should be for the remaining pixel. Sadly, I don't remember the specifics of the algorithm involved beyond that point.
katierosy
Forum Commoner
Posts: 27
Joined: Wed Apr 07, 2010 8:39 am

Re: Convert html table to an image using php

Post by katierosy »

If you can get one php html to image converter it will help.
Post Reply