在laravel中将.heic图像转换为jpg图像格式

问题描述 投票:0回答:1

我添加了intervention / image包以在laravel中转换图像格式。

图像转换成功,但是上传图像质量很差。

原始图像Original Image

上传的图片Uploaded Image

image blur

$img =(string) Image::make($image['base64'])
    ->resize(500, 500)->encode('jpg',100);;
$img = base64_encode($img);
laravel imagemagick-convert heic
1个回答
0
投票

要转换Heic图像,您必须使用imagick,可以使用它代替吗

try {
    $image = new \Imagick();
    $image->readImageBlob($image['base64']));
    $image->setImageFormat("jpeg");
    $image->setImageCompressionQuality(100);
    $image->writeImage($targetdir.$uid.".jpg"); 
} 
catch (\ImagickException $ex) {
    /**@var \Exception $ex */
    return new JSONResponse(["error" => "Imagick failed to convert the images, check if you fulfill all requirements." , "details" => $ex->getMessage()], Http::STATUS_INTERNAL_SERVER_ERROR);
}
© www.soinside.com 2019 - 2024. All rights reserved.