/**
* 功能:產生縮圖
* 作者:phpox
* 日期:Thu May 17 09:57:05 CST 2007
*/
class CreatMiniature
{
//公共變數
var $srcFile=""; //原圖
var $echoType ; //輸出圖片類型,link--不儲存為檔案;file--儲存為檔案
var $im=""; //臨時變數
var $srcW=""; //原圖寬
var $srcH=""; //原圖高
//設定變數及初始化
function SetVar($srcFile,$echoType)
{
if (!file_exists($srcFile )){
echo '來源圖片檔案不存在!';
exit();
}
$this->srcFile=$srcFile;
$this->echoType=$echoType ;
$info = "";
$data = GetImageSize($this->srcFile,$info);
switch ($data[2])
{
case 1:
if(!function_exists("imagecreatefromgif")){
echo "你的GD庫不能使用GIF格式的圖片,請使用Jpeg或PNG格式!返回";
exit ();
}
$this->im = ImageCreateFromGIF($this->srcFile);
break;
case 2:
if(!function_exists("imagecreatefromjpegagecreatefromjpeg")){
echo "你的GD庫不能使用jpeg格式的圖片,請使用其它格式的圖片!回傳";
exit();
}
$this->im = ImageCreateFromJpeg($this->srcFile);
break;
情況3:
$this->im = ImageCreateFromPNG($this->srcFile)
break;
$this->srcW=ImageSX($this-> ;im); =ImageSY($this->im) ;
}
//產生變形模型縮圖
function Distortion($toFile,$toW, $toH)
{
$cImg=$ this->CreatImage($this-> im,$toW,$toH,0,0,0,0,$this->srcW,$this ->srcH);
return $this->EchoImage( $cImg,$toFile);
ImageDestroy($cImg);
}
//產生按比例縮放的縮小圖
函數按比例分配($toFile,$toW,$toH )
{
$toWH=$toW/$toH;
$srcWH=$toWH=$toW/$toH;
$srcWH=$this->srcW/$this->srcH;
if($toWH {
$ ftoW=$toW;
$ftoH=$ftoW*($this->srcH/$this->srcW);
}
其他
{
$ftoH =$toH;
$ftoW=$ftoH*($this->srcW/$this->srcH)
}
if($this->srcW>$toW||$this->srcH >$toH)
{
$cImg=$this->CreatImage($this->im, $ftoW,$ftoH,0,0,0,0,$this->srcW,$this-> srcH);
返回$this->EchoImage($cImg,$toFile);
ImageDestroy($cImg);
}
其他
{
$cImg=$this- >CreatImage($this ->im,$this->srcW,$this->srcH,0,0, 0,0,$this->srcW,$this->srcH);
return $this->EchoImage($cImg,$toFile);
ImageDestroy($cImg);
}
}
//產生最小縮小後的縮圖
function Cut($toFile,$toW,$toH.)
{
$toWH=$ toW/ $到H;
$srcWH=$this->srcW/$this->srcH;
if($toWH{
$ctoH=$toH;
$ctoW=$ctoH*($this->srcW/$this->srcH);
}
其他
{
$ctoW=$toW;
$ctoH=$ctoW*($this->srcH/$this->srcW);
}
$allImg=$this->CreatImage($this->im,$ctoW,$ctoH,0,0,0,0,$this->srcW,$this->srcH);
$cImg=$this->CreatImage($allImg,$toW,$toH,0,0,($ctoW-$toW)/2,($ctoH-$toH)/2,$ toW, $到H);
return $this->EchoImage($cImg,$toFile);
ImageDestroy($cImg);
ImageDestroy($allImg);
//產生背景填充的縮圖
function BackFill($toFile,$toW,$toH,$bk1=255,$bk2=255,$bk3=255)
{
$toWH=$toW/ $toH;
$srcWH=$this->srcW/$this->srcH;
if($toWH{
$ftoW=$toW
$; ftoH=$ftoW*($this->srcH/$this->srcW)
}
其他
{
$ftoH=$toH;
$ftoW=$ftoH*( $ this->srcW/$this->srcH);
}
if(function_exists("imagecreatetruecolor"))
{
@$cImg=ImageCreateTrueColor($toW,$toW,$toW,$to ) ;
if(!$cImg)
{
$cImg=ImageCreate($toW,$toH🎜>$cImg=ImageCreate($toW,$toH🎜>{🎜>}
}
其他
{🎜>}
}
其他
{
$cImg=ImageCreate($toW,$toH);
}
$backcolor = imagecolorallocate($cImg, $bk1, $bk2, $bk3); // 填滿背景顏色
ImageFilledRectangle( $cImg,0,0,$toW,$toH,$backcolor)
if($this->srcW>$toW||$this->srcH>$toH)
{
$proImg=$this->CreatImage($this->im, $ftoW,$ftoH,0,0,0,0,$this->srcW,$this->srcH);
if($ftoW{
ImageCopy($cImg,$proImg,($toW-$ftoW)/2,0,0,0,$ftoW,$ftoH);
}
else if($ftoH{
ImageCopy($cImg,$proImg,0,($toH-$ftoH)/2,0,0,$ftoW, $ftoH);
}
其他
{
ImageCopy($cImg,$proImg,0,0,0,0,$ftoW,$ftoH);
}
}
其他
{
ImageCopyMerge($cImg,$this->im,($toW-$ftoW)/2,($toH-$ftoH)/2 , 0,0,$ftoW,$ftoH,100);
}
return $this->EchoImage($cImg,$toFile);
ImageDestroy($cImg);
}
函數CreatImage($img,$creatW,$creatH,$dstX,$dstY,$srcX,$srcY,$srcImgW,$srcImgH)
{
if(function_exists(true" ) ) "))
{
@$creatImg = ImageCreateTrueColor($creatW,$creatH);
if($creatImg)
ImageCopyResampled($creatImg,$img,$dstX,$dstY,$srcX,$srcY,$creatW,$creatH,$srcImgW,$srcImgH);
其他
{
$creatImg=ImageCreate($creatW,$creatH);
ImageCopyResized($creatImg,$img,$dstX,$dstY,$srcX,$srcY,$creatW,$creatH,$srcImgW,$srcImgH);
}
}
其他
{
$creatImg=ImageCreate($creatW,$creatH);
ImageCopyResized($creatImg,$img,$dstX,$dstY,$srcX,$srcY,$creatW,$creatH,$srcImgW,$srcImgH);
}
回傳 $creatImg;
}
//輸出圖片,連結---只輸出,不儲存檔案。 $this->echoType)
{
case "link":
if(function_exists('imagejpeg')) return ImageJpeg($img);
否則回傳ImagePNG($img);
休息;
case "file":
if(function_exists('imagejpeg')) return ImageJpeg($img,$to_File);
否則回傳ImagePNG($img,$to_File);
休息;
}
}
}
?
以上就介紹了php產生了php產生了大概的一類程式碼,包含了php產生了大概方面的內容,希望對PHP教學有興趣的朋友有幫助。

PHP用於構建動態網站,其核心功能包括:1.生成動態內容,通過與數據庫對接實時生成網頁;2.處理用戶交互和表單提交,驗證輸入並響應操作;3.管理會話和用戶認證,提供個性化體驗;4.優化性能和遵循最佳實踐,提升網站效率和安全性。

PHP在數據庫操作和服務器端邏輯處理中使用MySQLi和PDO擴展進行數據庫交互,並通過會話管理等功能處理服務器端邏輯。 1)使用MySQLi或PDO連接數據庫,執行SQL查詢。 2)通過會話管理等功能處理HTTP請求和用戶狀態。 3)使用事務確保數據庫操作的原子性。 4)防止SQL注入,使用異常處理和關閉連接來調試。 5)通過索引和緩存優化性能,編寫可讀性高的代碼並進行錯誤處理。

在PHP中使用預處理語句和PDO可以有效防範SQL注入攻擊。 1)使用PDO連接數據庫並設置錯誤模式。 2)通過prepare方法創建預處理語句,使用佔位符和execute方法傳遞數據。 3)處理查詢結果並確保代碼的安全性和性能。

PHP和Python各有優劣,選擇取決於項目需求和個人偏好。 1.PHP適合快速開發和維護大型Web應用。 2.Python在數據科學和機器學習領域佔據主導地位。

PHP在電子商務、內容管理系統和API開發中廣泛應用。 1)電子商務:用於購物車功能和支付處理。 2)內容管理系統:用於動態內容生成和用戶管理。 3)API開發:用於RESTfulAPI開發和API安全性。通過性能優化和最佳實踐,PHP應用的效率和可維護性得以提升。

PHP可以輕鬆創建互動網頁內容。 1)通過嵌入HTML動態生成內容,根據用戶輸入或數據庫數據實時展示。 2)處理表單提交並生成動態輸出,確保使用htmlspecialchars防XSS。 3)結合MySQL創建用戶註冊系統,使用password_hash和預處理語句增強安全性。掌握這些技巧將提升Web開發效率。

PHP和Python各有優勢,選擇依據項目需求。 1.PHP適合web開發,尤其快速開發和維護網站。 2.Python適用於數據科學、機器學習和人工智能,語法簡潔,適合初學者。

PHP仍然具有活力,其在現代編程領域中依然佔據重要地位。 1)PHP的簡單易學和強大社區支持使其在Web開發中廣泛應用;2)其靈活性和穩定性使其在處理Web表單、數據庫操作和文件處理等方面表現出色;3)PHP不斷進化和優化,適用於初學者和經驗豐富的開發者。


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

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

Safe Exam Browser
Safe Exam Browser是一個安全的瀏覽器環境,安全地進行線上考試。該軟體將任何電腦變成一個安全的工作站。它控制對任何實用工具的訪問,並防止學生使用未經授權的資源。

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)