如何在php中裁剪图像时保留透明颜色?(仅保存在jpg文件中)
当用户裁剪图像时,我试图将源图像的透明颜色保留到目标图像。我认为只有当图像是gif或png类型时,才会显示黑色而不是透明颜色。我做错了什么 我也只想保存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
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
}
}
如果你搜索它,你可能会找到更多
遗憾的是,这并不像你想象的那么简单或直接