skip to Main Content

I want to upload image from base64 image in two version, one 250px another 650px with watermark and it give me back an error: Image source not readable

    $path = public_path().'/seller/uploads/'. $seller->id .'/'. $adsid;  
    $watermark = public_path().'/watermark.png';
    $Image = explode(";base64,", $img);
    $ImageName = $date;
    $ImageDecode = base64_decode($Image[1]);
    $thumb_name = $ImageName.'-thumb.jpg';
    $resize_name = $ImageName.'-resized.jpg';

Image::make($ImageDecode)->encode('jpg', 80)->orientate()->resize(250, null, function ($constraint) {
$constraint->aspectRatio();
})->save($path.'/'.$thumb_name);

Image::make($ImageDecode)->encode('jpg', 80)->orientate()->resize(650, null, function ($constraint) {
$constraint->aspectRatio();
})->insert($watermark, 'bottom-right', 10, 10)->save($path.'/'.$resize_name);

Error:

exception: "InterventionImageExceptionNotReadableException"
file:
"E:vendorinterventionimagesrcInterventionImageAbstractDecoder.php"
line: 351 message: "Image source not readable"

What I have missed?

xampp 
PHP Version 8.1.12
Laravel Framework 8.83.23

2

Answers


  1. Check the file folder names properly or not and also check the read permission for the folder you are trying to access through your code. Many time issue in such cases is the file/folder name

    Login or Signup to reply.
  2. use InterventionImageFacadesImage;
    use IlluminateSupportFacadesStorage;
    
    try {
        $path = public_path('seller/uploads/'.$seller->id.'/'.$adsid);
        $watermark = public_path('watermark.png');
        $Image = explode(";base64,", $img);
        $ImageName = $date;
        $ImageDecode = base64_decode($Image[1]);
        $thumb_name = $ImageName.'-thumb.jpg';
        $resize_name = $ImageName.'-resized.jpg';
    
        // Create thumbnail image
        Image::make($ImageDecode)
            ->encode('jpg', 80)
            ->orientate()
            ->resize(250, null, function ($constraint) {
                $constraint->aspectRatio();
            })
            ->save($path.'/'.$thumb_name);
    
        // Create resized image with watermark
        Image::make($ImageDecode)
            ->encode('jpg', 80)
            ->orientate()
            ->resize(650, null, function ($constraint) {
                $constraint->aspectRatio();
            })
            ->insert($watermark, 'bottom-right', 10, 10)
            ->save($path.'/'.$resize_name);
            
        // Optionally, you can store the images in Laravel storage instead of public_path
        // Uncomment the following lines if you want to use Laravel storage
        // $storagePath = 'seller/uploads/'.$seller->id.'/'.$adsid;
        // Storage::disk('public')->put($storagePath.'/'.$thumb_name, file_get_contents($path.'/'.$thumb_name));
        // Storage::disk('public')->put($storagePath.'/'.$resize_name, file_get_contents($path.'/'.$resize_name));
    
        // Success message
        echo 'Image processed successfully!';
    } catch (Exception $e) {
        // Handle the exception
        echo 'Error: '.$e -> getMessage();
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search