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
  • Do you mean that $manager->read('https://static-00.iconduck/assets.00/user-icon-1024x1024-dtzturco.png'); causes the error? – Olivier Commented Jan 30 at 10:29
  • Assuming that library can work with HTTP URLs instead of local file system paths - it might simply be a case of "bot protection." – C3roe Commented Jan 30 at 10:39
  • @C3roe Or an SSL issue because it's actually an HTTPS URL. – Olivier Commented Jan 30 at 10:46
  • @Olivier in older version of image intervention we can able to read cdn image url directly using $manager->read but in new version we have to use "file_get_contents" then read method – Sanmit Pawar Commented Feb 20 at 10:04
Add a comment  | 

1 Answer 1

Reset to default -1

Image 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