搜尋
首頁php教程php手册等比例生成缩略图的php程序

等比例生成缩略图的php程序

Jun 13, 2016 am 09:48 AM
php實現比例產生程式這個

等比例生成缩略图的php程序 这个程序很实现,但只是用来进来等比例生成缩略图哦,你要把文件上传到服务器,然后再由此函数来操作,有需要的朋友参考一下。

等比例生成缩略图的php教程程序
这个程序很实现,但只是用来进来等比例生成缩略图哦,你要把文件上传到服务器,然后再由此函数来操作,有需要的朋友参考一下。

function reSizeImg($imgSrc, $resize_width, $resize_height, $isCut=false) {
 //图片的类型
 $type = substr ( strrchr ( $imgSrc, "." ), 1 );
 //初始化图象
 if ($type == "jpg") {
  $im = imagecreatefromjpeg ( $imgSrc );
 }
 if ($type == "gif") {
  $im = imagecreatefromgif ( $imgSrc );
 }
 if ($type == "png") {
  $im = imagecreatefrompng ( $imgSrc );
 }
 //目标图象地址
 $full_length = strlen ( $imgSrc );
 $type_length = strlen ( $type );
 $name_length = $full_length - $type_length;
 $name = substr ( $imgSrc, 0, $name_length - 1 );
 $dstimg = $name . "_s." . $type;

 $width = imagesx ( $im );
 $height = imagesy ( $im );

 //生成图象
 //改变后的图象的比例
 $resize_ratio = ($resize_width) / ($resize_height);
 //实际图象的比例
 $ratio = ($width) / ($height);
 if (($isCut) == 1) //裁图
  {
  if ($ratio >= $resize_ratio) //高度优先
  {
   $newimg = imagecreatetruecolor ( $resize_width, $resize_height );
   imagecopyresampled ( $newimg, $im, 0, 0, 0, 0, $resize_width, $resize_height, (($height) * $resize_ratio), $height );
   ImageJpeg ( $newimg, $dstimg );
  }
  if ($ratio   {
   $newimg = imagecreatetruecolor ( $resize_width, $resize_height );
   imagecopyresampled ( $newimg, $im, 0, 0, 0, 0, $resize_width, $resize_height, $width, (($width) / $resize_ratio) );
   ImageJpeg ( $newimg, $dstimg );
  }
 } else //不裁图
 {
  if ($ratio >= $resize_ratio) {
   $newimg = imagecreatetruecolor ( $resize_width, ($resize_width) / $ratio );
   imagecopyresampled ( $newimg, $im, 0, 0, 0, 0, $resize_width, ($resize_width) / $ratio, $width, $height );
   ImageJpeg ( $newimg, $dstimg );
  }
  if ($ratio    $newimg = imagecreatetruecolor ( ($resize_height) * $ratio, $resize_height );
   imagecopyresampled ( $newimg, $im, 0, 0, 0, 0, ($resize_height) * $ratio, $resize_height, $width, $height );
   ImageJpeg ( $newimg, $dstimg );
  }
 }
 ImageDestroy ( $im );
}

调用方法简单,直接reSizeImg就可以了,参考很简单。

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
4 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

mPDF

mPDF

mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),