image
image copied to clipboard
Remove black background image from png files
I am working with image cropping and its working file but in case of png files it generates black background.
public static function ImageCrop($file,$arDetails = array()) {
$arReturn = array();
if(!empty($file))
{
//get filename with extension
$filenamewithextension = $file->getClientOriginalName();
//get filename without extension
$filename = pathinfo($filenamewithextension, PATHINFO_FILENAME);
//get file extension
$extension = $file->getClientOriginalExtension();
//filename to store
$filenametostore = $filename.'_'.time().'.'.$extension;
//make Directory
if(!file_exists(public_path($arDetails['szUploadDirectory']))) {
mkdir(public_path($arDetails['szUploadDirectory']), 777);
}
//make crop Directory
if(!file_exists(public_path($arDetails['szUploadDirectory'].'/crop'))) {
mkdir(public_path($arDetails['szUploadDirectory'].'/crop'), 777 );
}
///$file->move(public_path($arDetails['szUploadDirectory']), $filenametostore);
$path = public_path($arDetails['szUploadDirectory'].'/'.$filenametostore);
$image = Image::make($file);
$image->rotate($arDetails['rotation']);
$image->save($path);
// crop image
$img = Image::make(public_path($arDetails['szUploadDirectory'].'/'.$filenametostore));
$croppath = public_path($arDetails['szUploadDirectory'].'/crop/'.$filenametostore);
$img->crop((int)$arDetails['width'], (int)$arDetails['height'], (int)$arDetails['x'], (int)$arDetails['y']);
$img->save($croppath);
// you can save crop image path below in database
$szImagePath =$croppath;
$arReturn['szImagePath'] = ($arDetails['szUploadDirectory'].'/crop/'.$filenametostore);
$arReturn['szImageName'] = $filenametostore;
return $arReturn;
}
}
i have so
Duplicate of https://github.com/Intervention/image/issues/1251