使用php怎么按比例截取图片-创新互联

本篇文章为大家展示了使用php怎么按比例截取图片,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

创新互联建站是一家集网站建设,桦川企业网站建设,桦川品牌网站建设,网站定制,桦川网站建设报价,网络营销,网络优化,桦川网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

具体如下:

filename = 'img/test.jpg';
$all_type = array(
"jpg"  => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg"  , "exn"=>".jpg"),
"gif"  => array("create"=>"ImageCreateFromGIF" , "output"=>"imagegif"  , "exn"=>".gif"),
"jpeg"  => array("create"=>"ImageCreateFromjpeg", "output"=>"imagejpeg"  , "exn"=>".jpg"),
"png"  => array("create"=>"imagecreatefrompng" , "output"=>"imagepng"  , "exn"=>".png"),
"wbmp"  => array("create"=>"imagecreatefromwbmp", "output"=>"image2wbmp" , "exn"=>".wbmp")
);
$imgtype = getimagesize($filename);
$width = $imgtype[0];
$height = $imgtype[1];
$type = str_replace('image/','',$imgtype['mime']);
$func_create = $all_type[$type]['create'];
$func_output = $all_type[$type]['output'];
$x = $y =0;
if(($width * 100)>($height * 120))
{
$newwidth = ceil($height * 120/100);
$newheight = $height;
$x = ($width-$newwidth)/2;
}
elseif(($width * 100)<($height * 120))
{
$newheight = ceil($width * 100/120);
$newwidth = $width;
$y = ($height-$newheight)/2;
}
else
{
$newheight = $height;
$newwidth = $width; 
}
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = $func_create($filename);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $newwidth, $newheight);
// Output
$func_output($thumb,'a.jpeg');

上述内容就是使用php怎么按比例截取图片,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。


分享名称:使用php怎么按比例截取图片-创新互联
网页网址:http://scyanting.com/article/cepccs.html