- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我真的不明白为什么 GD 有不同的函数来加载图像,例如:
imagecreatefromjpeg()
imagecreatefrompng()
imagecreatefromgif()
如果图片是字符串的话只有一个函数?
imagecreatefromstring()
确实,将图像读入字符串并将其传递给函数要好得多,例如:
$imgBlob = file_get_contents($imagePath);
imagecreatefromstring($imageBlob);
unset($imgBlob); //> Free memory, but I am not interested in memory consumpation
?或者我错过了什么?这可能会给新用户带来潜在的困惑
也许他们只是忘记创建函数 imageCreateFromFile()
?
Ps. 当然,我对使用file_get_contents
方法的内存消耗不感兴趣
最佳答案
imagecreatefromstring()
对传递的图像类型运行一个开关,检查您的系统是否支持该图像类型,然后实际运行正确的 imagecreatefrom*
函数。
您可以查看源代码以查看:https://github.com/php/php-src/blob/master/ext/gd/gd.c?source=cc (函数的第 2280 行,它打开图像类型并调用正确的函数的第 2301 行)。
因此,imagecreatefromstring()
函数实际上只是一个辅助包装器。如果调用实际图像类型函数,不运行 _php_image_type
(第 2217 行),您将获得非常小的好处。
关于php - 为什么有imageCreateFromString就有imageCreateFrom*?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10963453/
尝试在 wordpress 管理界面中上传时,我收到主题中提到的错误。 我的服务器使用 php-fpm 运行 nginx,PHP 版本是 5.3.0。 我在谷歌上搜索了很多关于这个问题的信息,但我找不
我在 PHP 中调整图像大小时遇到问题;似乎从我使用 imagecreatefromstring 或 imagecreatefrompng 加载图像的那一刻起,颜色就会改变并褪色。 我知道我必须使
这段代码有什么问题? 我收到这些错误: 警告:imagecreatefromstring():gd-png:致命的 libpng 错误:读取错误:第 5 行 D:\wamp\www\img\inde
最好的使用方法是什么imagecreatefromstring()或 .bmp 的替代方法文件? 这样: $data = file_get_contents($path); $image = imag
我一直在努力让我的应用程序变得透明(它在存储图像之前动态调整图像大小),我认为在对 imagealphablending 和 imagesavealpha。源图像从未以适当的透明度加载! // Wit
通常我使用 imagecreatefromjpeg() 然后使用 getimagesize(),但是对于 Firefox 3 我需要绕过这个不同。所以现在我正在使用 imagecreatefromst
假设我的代码看起来像这样: "; // // more stuff here // ?> 我要替换什么/* 这里是什么? */这样我的图像数据就会显示出来? 谢谢。 最佳答案 What do I re
这是我的代码: $data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl' . 'BMVEUAAAD///+l2Z/dAAA
我正在使用 imagecreatefromstring,目前正在验证正确的图像文件格式。 所以一个链接: swqkdwfibqwfwf 不会工作,因为它不是有效的文件类型。但我刚刚发现了这一点: si
我正在使用 imagecreatefromstring,目前正在验证正确的图像文件格式。 所以一个链接: swqkdwfibqwfwf 不会工作,因为它不是有效的文件类型。但我刚刚发现了这一点: si
我正在使用axios通过ajax发送base64字符串。使用下面的方法,当它从 Base64 数据编码回 jpg 时,我会以某种方式丢失大量数据。我怎样才能在不丢失数据的情况下发送此信息? 我从输入中
以下是我获取图片的方式: $coverurl = 'https://api.someurl/api/v1/img/' . $somenumber . '/l'; //$iheaders contai
我在 Javascript 和 PHP 之间以字符串形式发送图像时遇到问题。到目前为止,我有: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAA
我有一个简单的服务,它使用通过 URL 传递的参数生成任何文本的 PNG 图像。参数之一是文本本身,其余参数是“字体”、“颜色”、“字体粗细”等。 这种 URL 的一个例子是: http://pics
有没有办法使用 imagecreatefromstring() 并以某种方式获取图像类型? 最佳答案 当您使用 imagecreatefrom... 方法时,图像将作为未压缩的位图加载到内存中。此时并
我正在尝试从我无法控制的外部站点加载图像。 大多数时候它工作正常(到目前为止测试了数百张图像)。 它现在给我一个特定图像的错误: imagecreatefromstring():gd-jpeg、lib
目前,如果用户将照片发布/上传到我的 PHP 脚本,我会从这样的代码开始 getimagesize($_FILES['picture1']['tmp_name']); 然后我对它做了更多的事情,但我也
我创建了一个脚本,其中我必须在运行时使用 64 位编码的字符串创建图像。我使用 PHP 的 imagecreatefromstring 函数,但它在我的基于 Windows XAMPP 的 PHP 中
以下 JavaScript 代码会将 SVG 字符串转换为图像 blob,然后可用于在浏览器中显示: var data = '' + '' + '' +
当我尝试在不正确的 png 图像上使用 php-gd 函数时,出现致命的 PHP 错误。这似乎是某种错误,因为根据函数文档(例如 imagecreatefrompng): * @return reso
我是一名优秀的程序员,十分优秀!