- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我在 PHP 中调整图像大小时遇到问题;似乎从我使用 imagecreatefromstring
或 imagecreatefrompng
加载图像的那一刻起,颜色就会改变并褪色。
我知道我必须使用 imagecreatetruecolor
来创建目标图像,但我什至没有做到这一点。
这里有几个例子来解释我得到的结果:
// This results in a discolored / faded image
$image = imagecreatefrompng('/path/to/my/image.png');
header('Content-Type: image/png');
imagepng($image);
die();
// This also results in a discolored / faded image
$image = imagecreatefrompng('/path/to/my/image.png');
$info = getimagesize('/path/to/my/image.png');
$sourceWidth = $info[0];
$sourceHeight = $info[1];
$resizedImage = imagecreatetruecolor($sourceWidth, $sourceHeight);
imagecopyresampled($resizedImage, $image, 0, 0, 0, 0, $sourceWidth, $sourceHeight, $sourceWidth, $sourceHeight);
header('Content-Type: image/png');
imagepng($resizedImage);
die();
// Obviously, this works flawlessly.
header('Content-Type: image/png');
echo file_get_contents('/path/to/my/image.png');
die();
显然,我一定遗漏了一些东西,但我已经查看了我能找到的每一个 SO 问题和答案,但没有找到解决我问题的方法。
你遇到过这个问题吗?我应该怎么做?
最佳答案
这个问题可能与颜色配置文件有关,因为 GD 似乎不支持颜色配置文件。例如,如果您的图像位于比 sRGB 具有更多颜色信息的 Adobe RGB 色彩空间中,则可能会发生这种情况。以下是有关该主题的更多信息:
https://devot-ee.com/add-ons/support/ce-image/viewthread/1085
一个可能的解决方案是使用 Photoshop 将图像转换为 sRGB(导出时有一个“转换为 sRGB”复选框)。
如果这不可能,您可以使用 ImageMagick而不是 GD,它(如上面的链接中所述)确实支持颜色配置文件。
关于php - imagecreatefromstring 更改图像颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56622658/
尝试在 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
我是一名优秀的程序员,十分优秀!