脚本宝典收集整理的这篇文章主要介绍了php – 如何创建.BMP文件的缩略图?,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
我查了一个文件,发现它的mime是image / x-ms-bmp.
但是,我无法从…函数中找到合适的imagecreate.
请建议.
已经有一些尝试创建功能来执行此操作.
您可以在PHP文档中的注释中找到一个健壮且文档齐全的版本:http://www.php.net/manual/en/function.imagecreatefromwbmp.php#86214
以下是该评论的功能,没有优秀的文档,这些文档更长,但更具可读性:
public function imagecreatefrombmp($p_sFile) { $file = fopen($p_sFile,"rb"); $read = fread($file,10); while(!feof($file)&&($read<>"")) $read .= fread($file,1024); $temp = unpack("H*",$read); $hex = $temp[1]; $header = substr($hex,108); if (substr($header,4)=="424d") { $header_parts = str_split($header,2); $width = hexdec($header_parts[19].$header_parts[18]); $height = hexdec($header_parts[23].$header_parts[22]); unset($header_parts); } $x = 0; $y = 1; $image = imagecreatetruecolor($width,$height); $body = substr($hex,108); $body_size = (strlen($body)/2); $header_size = ($width*$height); $usePadding = ($body_size>($header_size*3)+4); for ($i=0;$i<$body_size;$i+=3) { if ($x>=$width) { if ($usePadding) $i += $width%4; $x = 0; $y++; if ($y>$height) break; } $i_pos = $i*2; $r = hexdec($body[$i_pos+4].$body[$i_pos+5]); $g = hexdec($body[$i_pos+2].$body[$i_pos+3]); $b = hexdec($body[$i_pos].$body[$i_pos+1]); $color = imagecolorallocate($image,$r,$g,$b); imagesetpixel($image,$x,$height-$y,$color); $x++; } unset($body); return $image; }
以上是脚本宝典为你收集整理的php – 如何创建.BMP文件的缩略图?全部内容,希望文章能够帮你解决php – 如何创建.BMP文件的缩略图?所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。