PHP code instance: Picture into HTML

Source: Internet
Author: User

PHP   <style> body{} a{display:inline-block;width:1px;height:1px </style> <?php function Createimfromfile ($path) {if (!is_file ($path)) {throw new Exception ("File: $path not found!"); $info = getimagesize ($path ); Switch ($info [2]) {Case 1://gif $tim = Imagecreatefromgif ($path); $w = Imagesx ($tim); $h = Imagesy ($tim); $im = Imagecrea Tetruecolor ($w, $h); Imagecopy ($im, $tim, 0,0,0,0, $w, $h); Imagedestroy ($tim); Break Case 2://jpg $im = Imagecreatefromjpeg ($path); Break Case 3://png $im = Imagecreatefrompng ($path); Break Default:throw New Exception ("not support file type. File: $path "); return $im; }   $im = Createimfromfile ("d:\\aa.jpg"); $w = Imagesx ($im); $h = Imagesy ($im); $str = "<div>"; for ($i = 0; $i < $h; $i + +) {$str. = "<div>" for ($j = 0; $j < $w; $j + +) {$rgb = Str_pad (Dechex imagecolorat ($im , $j, $i)), 6, "0", str_pad_left); $str. = "<a style= ' background:# $rgb ' ></a>"; $str. = "</div>"; } $str. = "</div>"; Imagedestroy ($im); Echo $str; /* $rgb = Imagecolorat ($im, 100, 100); $r = ($rgb >>) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xff;*/?>      . NET:       protected string tmp = "";       protected void Page_Load (object sender, EventArgs e) {        bitmap BM = new Bitmap ("d:\\aa.jpg");         int w = BM. Width;         int h = BM. Height;         stringbuilder sb = new StringBuilder ();         color C;        &NBSP;SB. Append ("<div>");         for (int i = 0; i < H; i++) {           &NBSP;SB. Append ("<div>");             for (int j = 0; J < W; J +) {         &NBSP ;     &NBSP;C = BM. GetPixel (J,i);  &nbsp             &NBSP;SB. Append (String. Format ("<a style= ' background:#{0}{1}{2} ' ></a>", V (C.R), V (C.G), V (C.B)));            &NBSP,            &NBSP;SB. Append ("<div>");        &NBSP}        &NBSP;SB. Append ("</div>");           tmp = sb. ToString ();    &nbsp}       private string V (int V) {        return string. Format ("{0:x}", V). PadLeft (2, ' 0 ');     }   After I had solved his confusion step-by-step, I found: It was just a joke! Another explanation: There is no direct use of createimagefromgif in PHP because:
Imagecolorat returns the color index (position in the palette) for
palette based image or the color value for true col or images.

Imagecreatefromjpeg creates true color images, always.
Imagecreatefromgif creates always palette based images and
imagecreatefrompng creates either palette or True color ima GES as PNG
supports both image types.

http://bugs.php.net/bug.php?id=40801

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.