新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
php裁切圖片步驟是什么
本文操作環(huán)境:windows7系統(tǒng)、php7.4版、DELL G3電腦

成都創(chuàng)新互聯(lián)公司主要從事網(wǎng)站制作、網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)會(huì)昌,10余年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專業(yè),歡迎來電咨詢建站服務(wù):13518219792
php裁切圖片步驟是什么?
PHP實(shí)現(xiàn)圖片不變型裁剪及圖片按比例裁剪的方法
本文實(shí)例講述了PHP實(shí)現(xiàn)圖片不變型裁剪及圖片按比例裁剪的方法。分享給大家供大家參考,具體如下:
圖片不變型裁剪
$target_ratio){
// image-to-height
$cropped_width = $source_width;
$cropped_height = $source_width * $target_ratio;
$source_x = 0;
$source_y = ($source_height - $cropped_height) / 2;
}elseif ($source_ratio < $target_ratio){
//image-to-widht
$cropped_width = $source_height / $target_ratio;
$cropped_height = $source_height;
$source_x = ($source_width - $cropped_width) / 2;
$source_y = 0;
}else{
//image-size-ok
$cropped_width = $source_width;
$cropped_height = $source_height;
$source_x = 0;
$source_y = 0;
}
switch ($source_mime){
case 'image/gif':
$source_image = imagecreatefromgif($source_path);
break;
case 'image/jpeg':
$source_image = imagecreatefromjpeg($source_path);
break;
case 'image/png':
$source_image = imagecreatefrompng($source_path);
break;
default:
return ;
break;
}
$target_image = imagecreatetruecolor($target_width, $target_height);
$cropped_image = imagecreatetruecolor($cropped_width, $cropped_height);
// copy
imagecopy($cropped_image, $source_image, 0, 0, $source_x, $source_y, $cropped_width, $cropped_height);
// zoom
imagecopyresampled($target_image, $cropped_image, 0, 0, 0, 0, $target_width, $target_height, $cropped_width, $cropped_height);
header('Content-Type: image/jpeg');
imagejpeg($target_image);
imagedestroy($source_image);
imagedestroy($target_image);
imagedestroy($cropped_image);
}
$filename = "8fcb7a0831b79c61.jpg";
imageCropper($filename,200,200);
?>
圖片按比例裁剪
當(dāng)前名稱:php裁切圖片步驟是什么
文章鏈接:http://m.fisionsoft.com.cn/article/dpdccjs.html


咨詢
建站咨詢
