Important alert: (current site time 7/16/2013 7:30:39 AM EDT)
 

VB icon

IMG 2 HTML

Email
Submitted on: 8/19/2010 7:53:48 AM
By: Oliver Leuyim Angel / Curda  
Level: Intermediate
User Rating: By 2 Users
Compatibility: PHP 3.0, PHP 4.0, PHP 5.0
Views: 4519
author picture
(About the author)
 
     This code transforms or converts an image to an html pixel colored table. The purpose of the code is, if u want to send images in an html e-mail this code makes the images to be unblocked. The idea in the script is that takes pixel by pixel and transform to a in table The script is developed for to all browsers. No complication. RATE THE CODE.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: IMG 2 HTML
// Description:This code transforms or converts an image to an html pixel colored table.
The purpose of the code is, if u want to send images in an html e-mail this code makes the images to be unblocked.
The idea in the script is that takes pixel by pixel and transform to a <td> in table
The script is developed for to all browsers. 
No complication. 
RATE THE CODE.
// By: Oliver Leuyim Angel / Curda
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=2793&lngWId=8//for details.//**************************************

<?php
/*
 Autor: Oliver Leuyim Angel R.
 Web Page: http://dimworks.org
 Year: 2010
*/
$img = imagecreatefromjpeg("image1.jpg"); //for get image from jpeg uncomment & comment others 
//$img = imagecreatefromgif("image1.gif");//For get image from gifuncomment & comment others
//$img = imagecreatefrompng("image1.png");//for get image from pnguncomment & comment others 
 
$w = imagesx($img);
$h = imagesy($img);
$table = "";
$firstrow = 1; # Disable RLE for first row of each table segment (dodge Mozilla bug)
for($y=0;$y<$h;$y++) {
 $row = ""; 
 for($x=0;$x<$w;$x++) {
 $rgb = imagecolorat($img, $x, $y);
 $r = ($rgb >> 16) & 0xFF;
 $g = ($rgb >> 8) & 0xFF;
 $b = $rgb & 0xFF; 
 
 if ($x == $w) {
 # Dummy run to clear the colspan buffer.
 $rgb='';
} else {
 $rgb = str_repeat("0",2-strlen(dechex($r))).dechex($r).str_repeat("0",2-strlen(dechex($g))).dechex($g).str_repeat("0",2-strlen(dechex($b))).dechex($b);
}
 
if ($x == 0) { # Initialise the RLE (Run Length Encoding)
 $prev_rgb = $rgb;
 $span = 0;
}
$span++;
if ($rgb != $prev_rgb || $firstrow) {
 if ($span == 1) { # One pixel.
$row .= "<TD BGCOLOR=#$prev_rgb><img width=1 height=1></TD>";
 } else { # A run of multiple pixels with the same colour.
$row .= "<TD BGCOLOR=#$prev_rgb COLSPAN=$span><img width=1 height=1></TD>";
 }
 $span = 0;
 $prev_rgb = $rgb;
}
 }
 $table .= "<TR>$row</TR>\n"; 
 # Segment the table so that MSIE renders it in pieces instead of waiting till the end.
 if ($y != 0 && ($y == 5 || $y % 15 == 0) && $y < $h-10) {
$table .= "</TABLE><TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>\n";
$firstrow = 1;
 } else {
$firstrow = 0;
 }
 
}
$newsize = strlen($table)/1024 + 0.5;
echo "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0>".$table."</TABLE>";
?>


Other 10 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
9/10/2010 11:29:30 AMPhilip Birk-Jensen

I like the idea of using a table. I've written an article(http://birk-jensen.dk/articles/php/pic2html/pic2html.htm) where I do the same thing, except I'm using a pre HTML tag with fontsize of 1px.

But I concluded back then, that I couldn't find anything useful to do with the code. So out of curiosity, have you found any use for this in a real-world situation?
(If this comment was disrespectful, please report it.)

 
9/13/2010 6:11:32 PMCurda

Hi, Philip Birk-Jensen,

yes i have a good solution for this in the real-world, the situation is when u are sending a mail blast or spam mail, this makes to no block and show the images in mail.
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.