简体   繁体   English

如何在PHP GD中调整大小和颜色变化png图像

[英]How to do resize and color change png image in php GD

<?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");
}
?>

这里没有专家...经过一个月的研究和努力研究,到目前为止,我找到了上述解决方案的答案...就在几分钟前...我们必须使用imagecreate funciton代替imagecreatetruecolor ... coz trucolor函数生成32位png图像...我们无法使用imagecolorset函数对32位图像进行着色..它多么棘手..大声笑..感谢蜡笔的支持...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM