Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php GD中调整png图像的大小和颜色_Php_Image_Png_Colorize - Fatal编程技术网

如何在php GD中调整png图像的大小和颜色

如何在php GD中调整png图像的大小和颜色,php,image,png,colorize,Php,Image,Png,Colorize,这里没有专家。。。到目前为止,经过一个月的研究和努力学习,我找到了上述解决方案的答案……就在几分钟前。。。我们必须使用imagecreate函数而不是ImageCreateTureColor。。。因为trucolor函数生成32位png图像…我们无法使用imagecolorset函数为32位图像着色。。这是多么棘手啊……哈哈。。感谢您对蜡笔的支持…当您先更改颜色,然后调整大小时,上面的代码会起作用。但我需要相反的顺序。。。请帮助我如果您发布代码、XML或数据示例,请在文本编辑器中突出显示这些行,

这里没有专家。。。到目前为止,经过一个月的研究和努力学习,我找到了上述解决方案的答案……就在几分钟前。。。我们必须使用imagecreate函数而不是ImageCreateTureColor。。。因为trucolor函数生成32位png图像…我们无法使用imagecolorset函数为32位图像着色。。这是多么棘手啊……哈哈。。感谢您对蜡笔的支持…

当您先更改颜色,然后调整大小时,上面的代码会起作用。但我需要相反的顺序。。。请帮助我如果您发布代码、XML或数据示例,请在文本编辑器中突出显示这些行,并单击编辑器工具栏上的“代码示例”按钮(
{}
),以很好地格式化和语法突出显示它!可能是重复的是的,是我…我这里有一个代码蜡笔暴力-这是我修改的代码。。。请看一看。
<?php
createImage(50,50, 0,0, 255);
function createImage($width, $height, $nR, $nG, $nB)
{
$image = imagecreatefrompng("source.png");
imagealphablending($image, false);  
imagesavealpha($image, true);       

      //resize the image
      $new_image = imagecreatetruecolor($width, $height);
      imagealphablending($new_image, false); 
      imagesavealpha($new_image, true);
      imagecopyresampled($new_image, $image, 0, 0, 0, 0, $width, $height, imagesx($image), imagesx($image));

    //colorize the image
        $nrgb = str_pad(dechex($nR), 2, '0', STR_PAD_LEFT). str_pad(dechex($nG), 2, '0', STR_PAD_LEFT). str_pad(dechex($nB), 2, '0', STR_PAD_LEFT);              

       $newColor = $nrgb;

        $c2 = sscanf($newColor ,"%2x%2x%2x");

        for($i=0;$i<$width;$i++)
        {
            for($j=0;$j<$height;$j++)
            {
             $cIndex = imagecolorat($new_image,$i,$j);

             imagecolorset($new_image,$cIndex,$c2[0],$c2[1],$c2[2]);
            }
        }

        header("Content-Type: image/png");

        imagepng($new_image,"test.png");
}
?>