GD 如何做到这一点?
How to do that with GD?
使用 (t) .net/imagesx" rel="noreferrer">与源图像尺寸相同,然后复制 (s) 到 (t)。
例如(没有错误处理):
$imgSource = imagecreatefromgif('xyz.gif'); $width = imagesx($imgSource); $height = imagesy($imgSource); $imgTC = imagecreatetruecolor($width, $height); imagecopy($imgTC, $imgSource, 0, 0, 0, 0, $width, $height); // save or send $imgTC
您将在内存中以 gd2 格式保存两个图像(每像素 4 字节?5?),因此您最好检查您的 memory_limit 设置,然后再尝试使用较大的图像。
Create a new truecolor image resource (t) with the same dimensions as the source image (s) and then copy (s) to (t).
e.g. (without error handling):
You'll have both images in memory in the gd2 format (4 bytes per pixel? 5?), so you better check your memory_limit setting before trying this with larger images.
从 PHP 5.5 开始,有一个快速、简单且占用内存较少的解决方案:只需使用 imagepalettetotruecolor PHP 函数:
imagepalettetotruecolor
$imgSource = imagecreatefromgif('xyz.gif'); if (!imageistruecolor($imgSource)) { imagepalettetotruecolor($imgSource); }
Since PHP 5.5 there's a fast, easy and less memory-hungry solution: just use the imagepalettetotruecolor PHP function:
您需要做的就是使用 imagecreatetruecolor 创建一个新图像,然后 imagecopy 将基于调色板的图像复制到其上。
All you need to do is use imagecreatetruecolor to create a new image and then imagecopy your palette-based image onto it.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
暂无简介
文章 0 评论 0
接受
发布评论
评论(3)
使用 (t) .net/imagesx" rel="noreferrer">与源图像尺寸相同,然后复制 (s) 到 (t)。
例如(没有错误处理):
您将在内存中以 gd2 格式保存两个图像(每像素 4 字节?5?),因此您最好检查您的 memory_limit 设置,然后再尝试使用较大的图像。
Create a new truecolor image resource (t) with the same dimensions as the source image (s) and then copy (s) to (t).
e.g. (without error handling):
You'll have both images in memory in the gd2 format (4 bytes per pixel? 5?), so you better check your memory_limit setting before trying this with larger images.
从 PHP 5.5 开始,有一个快速、简单且占用内存较少的解决方案:只需使用
imagepalettetotruecolor
PHP 函数:Since PHP 5.5 there's a fast, easy and less memory-hungry solution: just use the
imagepalettetotruecolor
PHP function:您需要做的就是使用 imagecreatetruecolor 创建一个新图像,然后 imagecopy 将基于调色板的图像复制到其上。
All you need to do is use imagecreatetruecolor to create a new image and then imagecopy your palette-based image onto it.