源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

PHP载入图像imagecreatefrom_gif_jpeg_png系列函数用法分析

  • 时间:2022-03-16 16:24 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:PHP载入图像imagecreatefrom_gif_jpeg_png系列函数用法分析
本文实例分析了PHP载入图像imagecreatefrom_gif_jpeg_png系列函数用法。分享给大家供大家参考,具体如下: imagecreatefrom 系列函数用于从文件或 URL 载入一幅图像。 [b]载入图像[/b] imagecreatefrom 系列函数用于从文件或 URL 载入一幅图像,成功返回图像资源,失败则返回一个空字符串。 该系列函数有: [b]imagecreatefromgif():创建一块画布,并从 GIF 文件或 URL 地址载入一副图像 imagecreatefromjpeg():创建一块画布,并从 JPEG 文件或 URL 地址载入一副图像 imagecreatefrompng():创建一块画布,并从 PNG 文件或 URL 地址载入一副图像 imagecreatefromwbmp():创建一块画布,并从 WBMP 文件或 URL 地址载入一副图像 imagecreatefromstring():创建一块画布,并从字符串中的图像流新建一副图像[/b] [b]语法:[/b]
resource imagecreatefromgif( string filename )
resource imagecreatefromjpeg( string filename )
resource imagecreatefrompng( string filename )
resource imagecreatefromwbmp( string filename )
resource imagecreatefromstring( string image )

[b]例子:[/b]
<?
header("Content-type: image/jpeg");
//创建并载入一幅图像
$im = @imagecreatefromjpeg("images/flower_1.jpg");
//错误处理
if(!$im){
  $im = imagecreatetruecolor(150, 30);
  $bg = imagecolorallocate($im, 255, 255, 255);
  $text_color = imagecolorallocate($im, 0, 0, 255);
  //填充背景色
  imagefilledrectangle($im, 0, 0, 150, 30, $bg);
  //以图像方式输出错误信息
  imagestring($im, 3, 5, 5, "Error loading image", $text_color);
} else {
  //输出该图像
  imagejpeg($im);
}
?>
在该例子中,我们载入并输出原图。由于 PHP 对图像创建错误没有友好的错误提示,因此我们自定义了错误处理信息。 [b]提示[/b] 对于 PHP 生成的图片,如果要直接在普通网页中显示而不是通过 header 输出,可以通过如下的方式调用:
<img src="pic.php" />

更多关于PHP相关内容感兴趣的读者可查看本站专题:《[url=http://www.1sucai.cn/Special/455.htm]PHP图形与图片操作技巧汇总[/url]》、《[url=http://www.1sucai.cn/Special/59.htm]php文件操作总结[/url]》、《[url=http://www.1sucai.cn/Special/623.htm]PHP数组(Array)操作技巧大全[/url]》、《[url=http://www.1sucai.cn/Special/348.htm]PHP基本语法入门教程[/url]》、《[url=http://www.1sucai.cn/Special/357.htm]PHP运算与运算符用法总结[/url]》、《[url=http://www.1sucai.cn/Special/43.htm]php面向对象程序设计入门教程[/url]》、《[url=http://www.1sucai.cn/Special/495.htm]PHP网络编程技巧总结[/url]》、《[url=http://www.1sucai.cn/Special/47.htm]php字符串(string)用法总结[/url]》、《[url=http://www.1sucai.cn/Special/84.htm]php+mysql数据库操作入门教程[/url]》及《[url=http://www.1sucai.cn/Special/231.htm]php常见数据库操作技巧汇总[/url]》 希望本文所述对大家PHP程序设计有所帮助。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部