imagecreatefrompng() - gd函数(图像处理)
imagecreatefrompng()
(PHP 4, PHP 5, PHP 7)
由文件或 URL 创建一个新图象。
说明
imagecreatefrompng(string $filename): resourceimagecreatefrompng()返回一图像标识符,代表了从给定的文件名取得的图像。
Tip如已启用fopen 包装器,在此函数中, URL 可作为文件名。关于如何指定文件名详见fopen()。各种wapper 的不同功能请参见支持的协议和封装协议,注意其用法及其可提供的预定义变量。
参数
$filenamePNG 图像的路径。
返回值
成功后返回图象资源,失败后返回FALSE
。
范例
处理创建 PNG 过程中的错误
以上例程的输出类似于:
注释
WarningWindows 版本的 PHP 在 4.3.0版之前不支持通过此函数访问远程文件,即使已经启用allow_url_fopen.
If you're trying to load a translucent png-24 image but are finding an absence of transparency (like it's black), you need to enable alpha channel AND save the setting. I'm new to GD and it took me almost two hours to figure this out.
I had the same problem as jboyd1189 at yahoo dot com but I solve d it allocating more memory dynamically. Usually the memory_limit var on php.ini is set to 8M. Unfortunately, the required amount of memory to manage a PNG image about 1000x1000 could be bigger ! The approach I used to solve the problem is: 1-Calculate the memory required by the image 2-Set the new memory_limit value 3-Create the PNG image and thumbnail 4-Restore the original value 1-The following value works for me: $required_memory = Round($width * $height * $size['bits']); Note that for JPEG the requirements are not the same: http://es2.php.net/manual/en/function.imagecreatefromjpeg.php#60241 2-Use somthing like: $new_limit=memory_get_usage() + $required_memory; ini_set("memory_limit", $new_limit); 4-ini_restore ("memory_limit");
When using imagecreatepng with alpha blending you will lose the blending. To over come this use something like the following Where $width and $height are the width and height of the $src image. This will create a true colour image then copy the png image to this true colour image and retain alpha blending.
The image size (width x height) should not exceed INT_MAX ... It's still thrue on a 64 bits computer.
I have this code: if (exif_imagetype($this->img_name) == IMAGETYPE_PNG) { try { $this->image = imagecreatefrompng($this->img_name); Error::log('It is a png: '.$this->img_name); } catch (Exception $e) { echo "The image file has some strange charachters. Probably not a png image?"; $this->image = ''; $this->img_name = ''; } } And I get this error in the error.log: PHP Unknown error: imagecreatefrompng(): gd-png: fatal libpng error: Extra compressed data\n in Unknown on line 0 The file that I try to open is a generated .png image which I can open from gimp and Geeqie. What is the problem? Could you please help me?
I was having a terrible time with the imagecreatefrompng function as it was working perfectly for one image and not at all for another. After many hours of frustration, I discovered that the problem was the image size (number of pixels). It appears that the maximum number of pixels this function will process is 1,040,000. So, be sure that the pixel resolution of the image (eg. 1040 x 1000) does not exceed this value.
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)