Advertisement
Website/CMS Templates
PHP CMS Templates
Drupal Drupal
Dragonfly Dragonfly
e107 e107
Joomla Joomla
Mambo Mambo
phpNuke phpNuke
PostNuke PostNuke
Plone Plone
WordPress WordPress
Xoops Xoops
php Forum Template
phpBB phpBB
SMF SMF
IPB IPB
vBulletin vBulletin
ASP CMS Templates
Nukedit Nukedit
DotNetNuke DotNetNuke
ASP Forum Template
WebWiz WebWiz
HTML Templates
CSS CSS
HTML HTML
Flash Flash
Latest Downloads
preview Black and Red G...(22)
preview silhouette4...(12)
preview  I-Fusion v1.2 ...(150)
preview  cvsBLACKv2.1 v...(627)
preview BiZ-2-0...(15)
preview hl2v2_clanspy...(11)
preview Adc...(13)
preview Aquasoft...(13)
Mezophere Friends
Pixel2life.com Pixel2life.com
ProvokeYourMind.com ProvokeYourMind.com
Seek-The-Geek.com Seek-The-Geek.com
Sliech.com Sliech.com
Convert Images to tables or divs
This tutorial in no way will help your website.  There is no point to convert an image to a giant table or thoudands of divs.  However, it can be easily done, so why not do it.  I have created two scripts, one to output an image pixel by pixel in a table and the other pixel by pixel using divs. 
To begin lets take a gander at the code for the table image. 


The Table Method:
Below resides the code that will read an image pixel by pixel and spit out a huge amount of html code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
25
27
28
29
30
31
32
$p=$_GET['img'];

$filename = "upload/upimg/$p";

$imgFile = $filename;

$im = imagecreatefromjpeg($imgFile);

$imgWidth = imagesx($im);
$imgHeight = imagesy($im);


print "\n";
echo '<table cellspacing="0" cellpadding="0"><tr>';
for ($y=0; $y < $imgHeight; $y++)
{
echo '<tr>';
for ($x=0; $x < $imgWidth; $x++)
{

$ndx = imagecolorat($im,$x,$y);
$aryColors = imagecolorsforindex($im,$ndx);
$color= substr("0".dechex($aryColors['red']),-2);
$color.= substr("0".dechex($aryColors['green']),-2);
$color.= substr("0".dechex($aryColors['blue']),-2);

echo '<td bgcolor='.$color.'><img src="/linked_demos/images/space.gif" height="1" width="1"/></td>';
}
print "</tr>";
}
echo '</table>';
The break down:
Line number 1 simply pulls in the image request.  To use the script you would call it by using img in your link as follows: www.site.com/tablesfromimage.php?img=imagename.jpg
Line 3: The filename is set up as the full path to the file.
Line 7-10: Using GD we create an image from the desired image and get the height and width from this file.  The reason we create a new image is to have the ability to pick each pixel's color values.
Line 14: Begin the table--nothing special, just no padding and no spacing or else the image will be giant and pixelated. 
Line 15: This loop counts vertically the position on the image. Once it has gone through the number of vertical pixels it knows the image is complete
Line 18:  This for loop denotes a row of pixels.  While in this for loop you will output and entire row of the image 1 pixel at a time.  At the end of the loop the div will close and a new div will begin.
Line 21: This line gets the courrent pixel coordiates.  Depending on the position in each for loop x and y will have values that will correspond with the current pixel. That locations color information is then read in the following lines. 
Lines 23-25: This reads the RGB hex values of the pixel and sets up a string of hex digits. 
A table cell is then output with the background color set to the hex value read from the image.  A spacer, 1x1px transparent gif, is needed to make the cells the correct size in IE.

If you wish to try this script I suggest using a small image.  It is extrmely slow and a large image will most likely timeout before completion.



 
Graphics/Office Templates
Graphics Templates
GIMP GIMP
Illustrator Illustrator
Paint Shop Pro Paint Shop Pro
Photoshop Photoshop
Office Templates
Word Word
PowerPoint PowerPoint
Excel Excel
Publisher Publisher
Latest Tutorials
space 1: Convert Images to ...
space 2: 3D Text with centr...
space 3: Wheaties Logo...
space 4: Text made from Alu...
space 5: Popluar Beveled lo...
We have 13 guests online
| Tutorial Views: 51901 | Templates Indexed: 458 | Template Views: 28000 | Downloads: 7058
| © Mezophere.com
Valid XHTML 1.0and CSS