Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.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 帮助修复图像库_Php_Png_Transparency - Fatal编程技术网

Php 帮助修复图像库

Php 帮助修复图像库,php,png,transparency,Php,Png,Transparency,我的图像库有问题。我想我知道这个问题,但我对图像知之甚少,希望有人能告诉我到底出了什么问题 我想做的是调整.png的大小并保持透明度。当我调整大小并保存.png图像时,它会失去透明度并变为黑色 我认为问题在于resize函数中的imagecreatetruecolor函数。文档表明这会返回一个黑色图像。我想这不是我想要的 有人能不能多管闲事,告诉我问题是否真的出在resize函数上,以及如何解决这个问题 谢谢 class ResizeImage { // Load Image

我的图像库有问题。我想我知道这个问题,但我对图像知之甚少,希望有人能告诉我到底出了什么问题

我想做的是调整.png的大小并保持透明度。当我调整大小并保存.png图像时,它会失去透明度并变为黑色

我认为问题在于resize函数中的
imagecreatetruecolor
函数。文档表明这会返回一个黑色图像。我想这不是我想要的

有人能不能多管闲事,告诉我问题是否真的出在resize函数上,以及如何解决这个问题

谢谢

class ResizeImage {

    // Load Image
    function load($filename) {
        $image_info = getimagesize($filename);
        $this->image_type = $image_info[2];

        if( $this->image_type == IMAGETYPE_JPEG ) {
            $this->image = imagecreatefromjpeg($filename);
        } elseif( $this->image_type == IMAGETYPE_GIF ) {
            $this->image = imagecreatefromgif($filename);
        } elseif( $this->image_type == IMAGETYPE_PNG ) {
            $this->image = imagecreatefrompng($filename);
            imagealphablending($this->image, true);
            imagesavealpha($this->image, true);
        }
    }

        // Resize the image
        function resize($width,$height) {
        $new_image = imagecreatetruecolor($width, $height);
        imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
        $this->image = $new_image;
    }

        // Save the image
    function save($filename, $image_type='', $compression=100, $permissions=null) {
        if ($image_type != '') {
            $this->image_type = $image_type;
        }

        if( $this->image_type == IMAGETYPE_JPEG ) {
            imagejpeg($this->image,$filename,$compression);
        } elseif( $this->image_type == IMAGETYPE_GIF ) {
            imagegif($this->image,$filename);
        } elseif( $this->image_type == IMAGETYPE_PNG ) {
            imagepng($this->image,$filename);
        }
        if( $permissions != null) {
            chmod($filename,$permissions);
        }
    }
尝试使用,例如:

function resize($width,$height) {
        $new_image = imagecreatetruecolor($width, $height);
        imagesavealpha($new_image, true);
        imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
        $this->image = $new_image;
    }
尝试使用。检查