仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1429|回复: 19
打印 上一主题 下一主题

[学习教程] PHP网站制作之PHP代码实例:图片转成HTML

[复制链接]
逍遥一派 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-3 23:43:58 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
当然你可以把你最基本的功能放出来的时候就放出来,比如放到论坛上,让大家都参与,   </p> 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 = imagecreatetruecolor( $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 >> 16) & 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;         sb.Append("<div>");         for( int i = 0 ; i < h ; i++ ) {             sb.Append("<div>");             for( int j = 0 ; j < w ; j++ ) {                 c = bm.GetPixel(j,i);                 sb.Append(string.Format("<a style='background:#{0}{1}{2}'></a>" , V(c.R) , V( c.G) , V(c.B)));             }             sb.Append("<div>");         }         sb.Append("</div>");           tmp = sb.ToString();     }       private string V( int v ) {         return string.Format("{0:X}" , v).PadLeft(2 , '0');     }     等我一步一步解开他的搅浑后,发明:它只是一个笑话!   别的申明一下: 在PHP 里没有直接利用 createimagefromgif 是由于:
  1. imagecolorat returns the color index (position in the palette) for palette based image or the color value for true color images. imagecreatefromjpeg creates true color images, always. imagecreatefromgif creates always palette based images and imagecreatefrompng creates either palette or true color images as PNG supports both image types.
复制代码
http://bugs.php.net/bug.php?id=40801参加PHP开发学习,或许只是一次偶然的想法吧!只是想在走向社会之前体验、学习在一个公司或者说是项目团队之中如何去更有效的沟通、交流、共同合作,还有就是为毕业实习找工作增加伐码。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-6-10 13:01

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表