imagecreatefromgd()函數是PHP中的內置函數,用於從GD文件或URL創建新圖像。此外,可以在程序中處理此圖像。可以使用imagegd()函數將圖像轉換為GD格式。
用法:
resource imagecreatefromgd( string $filename )
參數:該函數接受單個參數$filename,該參數保存文件的名稱或URL。
返回值:成功時此函數返回圖像資源標識符,錯誤時返回FALSE。
下麵給出的程序說明了PHP中的imagecreatefromgd()函數:程序1(在瀏覽器中查看gd文件):
<?php
// Load the GD image from localfile
$im = imagecreatefromgd('geeksforgeeks.gd');
// Output the image to browser
imagegd($im);
imagedestroy($im);
?>
輸出:
This will load gd image in text form as it is not supported by browser.
程序2(將GD轉換為png並在瀏覽器中查看):
<?php
// As GD isn't supported in browser, it can be
// converted into PNG to be viewed in browser
// Load the GD image
$im = imagecreatefromgd('geeksforgeeks.gd');
// Output the image to browser
header("Content-Type:image/png");
imagepng($im);
imagedestroy($im);
?>
輸出:
計劃3(將GD轉換為jpg):
<?php
// Load the GD image
$im = imagecreatefromgd('geeksforgeeks.gd');
// Convert the image and save in local folder
imagejpeg($im, 'geeksforgeeks.jpg');
imagedestroy($im);
?>
輸出:
This will convert GD image into JPEG and save in local folder.
參考: https://www.php.net/manual/en/function.imagecreatefromgd.php
相關用法
- p5.js second()用法及代碼示例
- p5.js pow()用法及代碼示例
- PHP each()用法及代碼示例
- PHP Ds\Set xor()用法及代碼示例
- PHP next()用法及代碼示例
- d3.js d3.map.set()用法及代碼示例
- CSS var()用法及代碼示例
- p5.js day()用法及代碼示例
- CSS url()用法及代碼示例
- p5.js hue()用法及代碼示例
- d3.js d3.set.has()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
注:本文由純淨天空篩選整理自gurrrung大神的英文原創作品 PHP | imagecreatefromgd() function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。