I'm trying to preserve the transparent colors of a source image to a destination image, when a user crops an image. I think that black colors appears instead of transparent colors only if the image is of type gif or png. What have I done wrong?
I also only want to save the image in jpg-format
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
}
}