Intervention
在一个laravel应用程序中(就像所有人一样),遇到了一个问题,即裁剪图像时会在图像周围应用黑色边框,如下所示:
奇怪的是它保留了图像文件的透明度,然后用黑色填充图像的其余部分。
/**
* Accept parameter array (
'_token' => 'E1seBDvsEBj1aNpLmenIKkAoNSKct878tqnIwOQO',
'x' => 55,
'y' => '30',
'width' => '200',
'height' => '200',
'filename' => '1_somerandomhash.jpg',
)
*
* Move the given filename from TMP_ORG_LOGOS to ORGANIZATION_LOGOS_DIRECTORY, apply
* cropped dimensions, rename to organization slug name plus small random hash, return
* true or false
*
* @param array $params
* @return bool
*/
public function saveLogo(int $userId, array $params) : bool {
try{
$org = $this->userService->getUserDefaultOrg($userId);
$newImageName = $org->slug . '-' . uniqid() . '.png';
Image::make(getenv('TMP_ORG_LOGOS') . $params['filename'])
->crop(round($params['width']), round($params['height']),
round($params['x']), round($params['y']))
->save(getenv('ORGANIZATION_LOGOS_DIRECTORY') . $newImageName, 100);
$org->logo = $newImageName;
$org->save();
return true;
} catch (\Exception $e){
return false;
}
}
以前有人见过这个吗?有没有办法让这些黑边界变得透明?
编辑
我还应该提到,intervention正在使用php的默认GD库进行图像操作。