脚本宝典收集整理的这篇文章主要介绍了PHP:使用GD库时图像上的黑条,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
这是一个例子:
谢谢你的时间.
$filename = '../Store/PRojects/project-123.jpg'; $mime = mime_content_type($filename); list($w,$h) = getimagesize($filename); $prop = $w / $h; $new_w = 0; $new_h = 0; if ($prop <= 4/3) { $new_w = 320; $new_h = (int)floor($h*($new_w/$w)); } else { $new_h = 240; $new_w = (int)floor($w*($new_h/$h)); } $thumb = imagecreatetruecolor($new_w,$new_h); if (strcmp($mime,'image/png') == 0) { header('Content-type: image/png'); $source = imagecreateFrompng($filename); } else { header('Content-Type: image/jpeg'); $source = imagecreatefromjpeg($filename); } imagecopyresampled($thumb,$source,$new_w,$new_h,$w,$h); $filename = '../store/projects-thumbs/project-123.jpg'; $crop_data = array('x' => 0,'y' => 0,'width' => 320,'height'=> 240); $thumb = imagecrop($thumb,$crop_data); imagejpeg($thumb,$filename,100); imagedestroy($thumb); imagedestroy($source);
以上是脚本宝典为你收集整理的PHP:使用GD库时图像上的黑条全部内容,希望文章能够帮你解决PHP:使用GD库时图像上的黑条所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。