Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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中裁剪图像时保留透明颜色?(仅保存在jpg文件中)_Php_Image_Image Processing - Fatal编程技术网

如何在php中裁剪图像时保留透明颜色?(仅保存在jpg文件中)

如何在php中裁剪图像时保留透明颜色?(仅保存在jpg文件中),php,image,image-processing,Php,Image,Image Processing,当用户裁剪图像时,我试图将源图像的透明颜色保留到目标图像。我认为只有当图像是gif或png类型时,才会显示黑色而不是透明颜色。我做错了什么 我也只想保存jpg格式的图像 public function crop2ThumbNail($top, $left, $height, $width){ $this->imageResized = imagecreatetruecolor(100, 100); $type = strtolower(substr(strrchr($th

当用户裁剪图像时,我试图将源图像的透明颜色保留到目标图像。我认为只有当图像是gif或png类型时,才会显示黑色而不是透明颜色。我做错了什么

我也只想保存jpg格式的图像

public function crop2ThumbNail($top, $left, $height, $width){

    $this->imageResized = imagecreatetruecolor(100, 100);
    $type = strtolower(substr(strrchr($this->image,"."),1));
    if($type == "gif" or $type == "png"){
        imagecolortransparent($this->imageResized,imagecolorallocatealpha($this->imageResized, 0, 0, 0, 127));
        imagealphablending($this->imageResized, false);
        imagesavealpha($this->imageResized, true);
    }
    imagecopyresampled($this->imageResized, $this->image , 0, 0, $left, $top, 100, 100 , $width, $height);

public function saveImage($savePath, $imageQuality="75"){
    if (imagetypes() & IMG_JPG){
         imagejpeg($this->imageResized, $savePath, $imageQuality);
    }else{
             //Alert wrong format
    }
}

如果你搜索它,你可能会找到更多

遗憾的是,这并不像你想象的那么简单或直接