欧美成人午夜免费全部完,亚洲午夜福利精品久久,а√最新版在线天堂,另类亚洲综合区图片小说区,亚洲欧美日韩精品色xxx

扣丁學(xué)堂PHP培訓(xùn)簡述PHP圖片裁剪函數(shù)

2019-05-05 16:21:59 3753瀏覽

本篇文章扣丁學(xué)堂PHP培訓(xùn)小編給讀者們實(shí)例分享一下PHP圖片裁剪函數(shù)的具體代碼,對PHP開發(fā)技術(shù)感興趣或者是想要參加PHP培訓(xùn)的小伙伴就隨小編來了解一下吧。



扣丁學(xué)堂PHP培訓(xùn)簡述PHP圖片裁剪函數(shù)



/*
 * 圖片裁剪工具
 * 將指定文件裁剪成正方形
 * 以中心為起始向四周裁剪
 * @param $src_path string 源文件地址
 * @param $des_path string 保存文件地址
 * @param $des_w double 目標(biāo)圖片寬度
 * */
function img_cut_square($src_path,$des_path,$des_w=100){
  $img_info = getimagesize($src_path);//獲取原圖像尺寸信息
  $img_width = $img_info[0];//原圖寬度
  $img_height = $img_info[1];//原圖高度
  $img_type = $img_info[2];//圖片類型 1 為 GIF 格式、 2 為 JPEG/JPG 格式、3 為 PNG 格式
  if($img_type != 2 && $img_type != 3) return ;

  /*計(jì)算縮放尺寸*/
  if($img_height > $img_width){
    $scale_width = $des_w;//縮放寬度
    $scale_height = round($des_w / $img_width * $img_height);//縮放高度

    $src_y = round(($scale_height - $des_w)/2);
    $src_x = 0;
  }else{
    $scale_height = $des_w;
    $scale_width = round($des_w / $img_height * $img_width);

    $src_y = 0;
    $src_x = round(($scale_width - $des_w)/2);
  }

  $dst_ims = imagecreatetruecolor($scale_width, $scale_height);//創(chuàng)建真彩畫布
  $white = imagecolorallocate($dst_ims, 255, 255, 255);
  imagefill($dst_ims, 0, 0, $white);
  if($img_type == 2){
    $src_im = @imagecreatefromjpeg($src_path);//讀取原圖像
  }else if($img_type == 3){
    $src_im = @imagecreatefrompng($src_path);//讀取原圖像
  }

  imagecopyresized($dst_ims, $src_im, 0, 0 ,0, 0 , $scale_width , $scale_height , $img_width,$img_height);//縮放圖片到指定尺寸


  $dst_im = imagecreatetruecolor($des_w, $des_w);
//  $white = imagecolorallocate($dst_im, 255, 255, 255);
//  imagefill($dst_im, 0, 0, $white);
  imagecopy($dst_im, $dst_ims, 0, 0, $src_x, $src_y, $des_w, $des_w);//開始裁剪圖片為正方形
// imagecopyresampled($dst_im, $src_im, $src_x, $src_y, 0, 0, $real_width, $real_width,$img_width,$img_height);
  if($img_type == 2) {
    imagejpeg($dst_im, $des_path);//保存到文件
  }else if($img_type == 3){
    imagepng($dst_im,$des_path);
  }
//  imagejpeg($dst_im);//輸出到瀏覽器
  imagedestroy($dst_im);
  imagedestroy($dst_ims);
  imagedestroy($src_im);
}



想要了解更多關(guān)于PHP開發(fā)方面內(nèi)容的小伙伴,請關(guān)注扣丁學(xué)堂PHP培訓(xùn)官網(wǎng)、微信等平臺,扣丁學(xué)堂IT職業(yè)在線學(xué)習(xí)教育有專業(yè)的PHP講師為您指導(dǎo),此外扣丁學(xué)堂老師精心推出的PHP視頻教程定能讓你快速掌握PHP從入門到精通開發(fā)實(shí)戰(zhàn)技能??鄱W(xué)堂PHP技術(shù)交流群:374332265。


扣丁學(xué)堂微信公眾號                          Python全棧開發(fā)爬蟲人工智能機(jī)器學(xué)習(xí)數(shù)據(jù)分析免費(fèi)公開課直播間


【關(guān)注微信公眾號獲取更多學(xué)習(xí)資料】         【掃碼進(jìn)入Python全棧開發(fā)免費(fèi)公開課】



查看更多關(guān)于“php培訓(xùn)資訊”的相關(guān)文章>>


標(biāo)簽: PHP培訓(xùn) PHP基礎(chǔ)教程 PHP學(xué)習(xí)視頻 PHP教學(xué)視頻 PHP入門教程 PHP教程視頻 PHP在線學(xué)習(xí) PHP在線視頻 PHP在線教程 扣丁學(xué)堂PHP培訓(xùn)

熱門專區(qū)

暫無熱門資訊

課程推薦

微信
微博
15311698296

全國免費(fèi)咨詢熱線

郵箱:codingke@1000phone.com

官方群:148715490

北京千鋒互聯(lián)科技有限公司版權(quán)所有   北京市海淀區(qū)寶盛北里西區(qū)28號中關(guān)村智誠科創(chuàng)大廈4層
京ICP備2021002079號-2   Copyright ? 2017 - 2022
返回頂部 返回頂部