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
相關用法
- p5.js pow()用法及代碼示例
- CSS url()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- PHP each()用法及代碼示例
- PHP next()用法及代碼示例
- p5.js second()用法及代碼示例
- p5.js day()用法及代碼示例
- PHP pow( )用法及代碼示例
- CSS var()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- d3.js d3.set.has()用法及代碼示例
- p5.js hue()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | imagegd2() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。