当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


PHP imagexbm()用法及代码示例

imagexbm()函数是PHP中的内置函数,用于显示图像以浏览文件。此函数的主要用途是在浏览器中查看图像并将任何其他图像类型转换为XBM。

用法:

bool imagexbm( resource $image, int $to, int $foreground)

参数:此函数接受上述和以下所述的三个参数:


  • $image:它指定要处理的图像资源。
  • $to (Optional):它指定将文件保存到的路径。
  • $foreground (Optional):它指定图像的前景。

返回值:如果成功,此函数将返回TRUE,否则将返回FALSE。

以下示例说明了PHP中的imagexbm()函数:

范例1:在此示例中,我们将在浏览器中下载图像。

<?php 
  
// Load an xbm image from local folder 
// Image can be converted into xbm using 
// online convertors or imagexbm() 
$im = imagecreatefromxbm('geeksforgeeks.xbm'); 
  
// Download the image 
header('Content-Type:image/xbm'); 
imagexbm($im); 
imagedestroy($im); 
?>

输出:

This will download your image as download, 
further you can rename this file to anything like 
geeksforgeeks.xbm and use it.

范例2:在此示例中,我们将PNG转换为XBM。

<?php 
  
// Load an image from PNG URL 
$im = imagecreatefrompng( 
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); 
  
// Convert the image into XBM using imagexbm() function 
imagexbm($im, 'converted.xbm'); 
imagedestroy($im); 
?>

输出:

This will save the XBM version of image in the same 
folder where your PHP script is.

参考: https://www.php.net/manual/en/function.imagexbm.php



相关用法


注:本文由纯净天空筛选整理自gurrrung大神的英文原创作品 PHP | imagexbm() Function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。