當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


PHP imagegd2()用法及代碼示例

imagegd2()函數是PHP中的內置函數,用於將GD2圖像輸出到瀏覽器或文件。這對於將任何其他圖像類型轉換為gd2最有用。 imagecreatefromgd2()函數可用於進一步讀取gd2圖像。

用法:

bool imagegd2( resource $image, float $to, 
             int $chunk_size, int $type )

參數:該函數接受上述和以下所述的四個參數:


  • $image:它指定要處理的圖像。
  • $to (Optional):它指定將文件保存到的路徑。
  • $chunk_size(可選):它指定塊的大小。
  • $type (Optional):它指定要使用的壓縮類型,可以是IMG_GD2_RAW或IMG_GD2_COMPRESSED中的一種。

返回值:如果成功,則此函數返回TRUE;如果失敗,則返回FALSE。

異常:該函數在出錯時引發Exception。

以下示例說明了PHP中的imagegd2()函數:

範例1:查看GD2文件。

<?php 
  
// Create a blank image and add text 
$im = imagecreatetruecolor(200, 200); 
$text_color = imagecolorallocate($im, 233, 14, 91); 
imagestring($im, 0, 30, 30,  "GeeksforGeeks", $text_color); 
  
// Output the image as string 
imagegd2($im); 
?>

輸出:

This will output the image in the form of string
as gd2 isn't supported in browser.

範例2:將圖像轉換為GD2。

<?php 
  
// Create a image from png 
$im = imagecreatefrompng( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
// Convert into GD2 and save to the same folder 
imagegd2($im, 'geeksforgeeks.gd2'); 
?>

輸出:

This will save a image with name geeksforgeeks.gd2 in the same folder.

參考: https://www.php.net/manual/en/function.imagegd2.php



相關用法


注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | imagegd2() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。