- Joined
- Apr 9, 2008
- Messages
- 1,416
- Reaction score
- 169
i thought it would be nice to release mine hehe. have fun but please add some credit to me if you use mine or give credit to apolva if he is releases his (link - http://forum.ragezone.com/f86/image2html-656985/).
it uses cURL to check if the link is valid. then it checks for the file extension to use the correct image grabber thingy. i also added a feature to change the output string.
EDIT:
updated the getPixel function. the old one outputted crappy span tags so now it looks way better.
PHP:
<?php
class Image {
function __construct() {
$this->cURL = curl_init();
}
public function setImage($image) {
$ext = pathinfo($image);
switch($ext['extension']) {
case "gif":$getImage=@ImageCreateFromGIF($image);break;
case "jpg":$getImage=@ImageCreateFromJPEG($image);break;
case "jpeg":$getImage=@ImageCreateFromJPEG($image);break; //?
case "png":$getImage=@ImageCreateFromPNG($image);break;
default:die("Not Supported Image Extension.");break;
}
!$getImage?die("Error in File Extension"):$this->image = $getImage;
$this->xy = $image;
}
public function rgb2hex($r,$g,$b) {
$r = dechex($r);
$g = dechex($g);
$b = dechex($b);
$color .= (strlen($r)<2?'0':'').$r;
$color .= (strlen($g)<2?'0':'').$g;
$color .= (strlen($b)<2?'0':'').$b;
return "#{$color}";
}
public function getPixel($x,$y) {
$RGB = ImageColorAt($this->image, $x, $y);
$color = ImageColorsForIndex($this->image, $RGB);
return "<td bgcolor=\"{$this->rgb2hex($color[red],$color[green],$color[blue])}\" width=\"1\"></td>";
}
public function getXY($xy) {
list($imageWidth, $imageHeight, $imageType, $imageAttr) = GetImageSize($this->xy);
if($xy == 'x')
return $imageWidth;
else
return $imageHeight;
}
public function checkURL($URL) {
curl_setopt($this->cURL, CURLOPT_URL, $URL);
curl_setopt($this->cURL, CURLOPT_HEADER, 0);
curl_setopt($this->cURL, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->cURL, CURLOPT_TIMEOUT, 5);
if(!curl_exec($this->cURL))
return false;
else
return true;
}
function __destruct() {
curl_close($this->cURL);
}
}
$Image = new Image;
if(!$_POST['submit']){
echo "<form method=\"POST\">";
echo "<center><table border=\"0\" width=\"300\"><tbody>";
echo "<tr><td style=\"font-weight: bold; text-align: right;\">Image URL:</td><td><input value=\"http://\" name=\"url\"></td></tr>";
echo "<tr><td style=\"text-align: center;\" colspan=\"2\"><input type=\"submit\" style=\"margin: 10px;\" value=\"Convert\" name=\"submit\"></td></tr>";
echo "</tbody></table></center>";
echo "</form>";
} else {
if($Image->checkURL($_POST['url'])) {
$Image->setImage($_POST['url']);
$width = $Image->getXY('x');
$height = $Image->getXY('y');
echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
for(;$y<$height;$y++) {
echo "<tr height=\"1\">";
for($x=0;$x<$width;$x++) {
echo $Image->getPixel($x,$y);
}
echo "</tr>";
}
echo "</table>";
} else {
die("Please Enter a Valid URL.");
}
}
?>
EDIT:
updated the getPixel function. the old one outputted crappy span tags so now it looks way better.
Last edited: