admin管理员组文章数量:1315784
in following code i am when passing image from my public_path its working but when i am padding another image as URL i am getting error like "Unable to decode input". i am using Laravel 11, Intervention package version 3 i.e latest & PHP version 8.2
// create an test image from a file
$manager = ImageManager::gd();
$image = $manager->read(public_path('images/templates/id-card.png'));
$anotherimage = $manager->read('.00/user-icon-1024x1024-dtzturco.png');
// resize to 300 x 200 pixel
$anotherimage->resize(300, 200);
// resize only image height to 200 pixel
$anotherimage->resize(height: 200);
// paste another image
$image = $image->place(
$anotherimage,
10,
10,
25
);
// Encode the image to JPG format (using encode method properly)
$encodedImage = $image->encode(); // This should work if 'jpg' is passed as a string
// Check if encoding works properly
if (!$encodedImage) {
return response('Error encoding image', 500);
}
// Stream the image response with correct headers
return Response::make($encodedImage, 200, [
'Content-Type' => 'image/jpeg',
]);
in following code i am when passing image from my public_path its working but when i am padding another image as URL i am getting error like "Unable to decode input". i am using Laravel 11, Intervention package version 3 i.e latest & PHP version 8.2
// create an test image from a file
$manager = ImageManager::gd();
$image = $manager->read(public_path('images/templates/id-card.png'));
$anotherimage = $manager->read('https://static-00.iconduck/assets.00/user-icon-1024x1024-dtzturco.png');
// resize to 300 x 200 pixel
$anotherimage->resize(300, 200);
// resize only image height to 200 pixel
$anotherimage->resize(height: 200);
// paste another image
$image = $image->place(
$anotherimage,
10,
10,
25
);
// Encode the image to JPG format (using encode method properly)
$encodedImage = $image->encode(); // This should work if 'jpg' is passed as a string
// Check if encoding works properly
if (!$encodedImage) {
return response('Error encoding image', 500);
}
// Stream the image response with correct headers
return Response::make($encodedImage, 200, [
'Content-Type' => 'image/jpeg',
]);
Share
Improve this question
asked Jan 30 at 10:12
Sanmit PawarSanmit Pawar
2433 silver badges10 bronze badges
4
|
1 Answer
Reset to default -1Image intervention V3 has so many changes and new functions. which we generally used in V2 is not available in V3 as we are doing in V2 so i have resolved the issue by doing following.
// create an test image from a file
$manager = ImageManager::gd();
// nonmal image called from storage path
$image = $manager->read(public_path('images/templates/id-card.png'));
// image called from URL have to do like below
$anotherimage = file_get_contents('https://plus.unsplash/premium_photo-1683121366070-5ceb7e007a97?fm=jpg&q=60&w=3000&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxzZWFyY2h8MXx8dXNlcnxlbnwwfHwwfHx8MA%3D%3D');
$anotherimage = $manager->read($anotherimage);
by just initially adding "file_get_contents()" you can read the image in Image intervention V3
本文标签: phpUnable to decode inputLaravelImage InterventionStack Overflow
版权声明:本文标题:php - Unable to decode input | Laravel | Image Intervention - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741973763a2407997.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$manager->read('https://static-00.iconduck/assets.00/user-icon-1024x1024-dtzturco.png');
causes the error? – Olivier Commented Jan 30 at 10:29