Why did I fail to add border to image with resizeCanvas of intervention/image?

31 Views Asked by At

In laravel 10 app with intervention/image 3.4 I try to make an border on source image and looking at the example https://github.com/Intervention/image/issues/1120#issuecomment-962696288 I use resizeCanvas method to image :

    $this->transformImageManager = new ImageManager(new Driver());
    $image = $this->transformImageManager->read($this->sourceImagePath);
    if ( ! empty($this->height) and empty($this->width)) {
        $image->resize(height: $this->height ?? null, width: $this->width ?? null);
    }

    $border_width = 10;
    $border_colour = '#a1fff9';
    $image->resizeCanvas($border_width*2, $border_width*2, 'center', true, $border_colour);   // ERROR POINTING TO THIS LINE

But I got an error :

   Intervention\Image\Exceptions\DecoderException

  Unable to decode input

  at vendor/intervention/image/src/Drivers/AbstractDecoder.php:37
     33▕         try {
     34▕             $decoded = $this->decode($input);
     35▕         } catch (DecoderException $e) {
     36▕             if (!$this->hasSuccessor()) {
  ➜  37▕                 throw new DecoderException($e->getMessage());
     38▕             }
     39▕
     40▕             return $this->successor->handle($input);
     41▕         }

      +19 vendor frames
  20  app/Library/TransformImage.php:93
      Intervention\Image\Image::resizeCanvas()

  21  app/Console/Commands/TestTransformImageCommand.php:55

I am not sur if resizeCanvas is applied to $image var? Or how to get canvas object from $image ?

If I check what is in $image var I see :

dd($image);


>Intervention\Image\Image^ {#2331
  #origin: Intervention\Image\Origin^ {#2336
    #mediaType: "image/jpeg"
    #filePath: "/_wwwroot/lar/MngProducts/public/images/active_products.jpg"
  }
  #blendingColor: Intervention\Image\Colors\Rgb\Color^ {#2337
    #channels: array:4 [
      0 => Intervention\Image\Colors\Rgb\Channels\Red^ {#2338
        #value: 255
      }
      1 => Intervention\Image\Colors\Rgb\Channels\Green^ {#2340
        #value: 255
      }
      2 => Intervention\Image\Colors\Rgb\Channels\Blue^ {#2341
        #value: 255
      }
      3 => Intervention\Image\Colors\Rgb\Channels\Alpha^ {#2342
        #value: 0
      }
    ]
  }
  #driver: Intervention\Image\Drivers\Gd\Driver^ {#2332}
  #core: Intervention\Image\Drivers\Gd\Core^ {#2333
    #items: array:1 [
      0 => Intervention\Image\Drivers\Gd\Frame^ {#2334
        #native: GdImage {#2330
          +size: "553x185"
          +trueColor: true
        }
        #delay: 0.0
        #dispose: 1
        #offset_left: 0
        #offset_top: 0
      }
    ]
    #loops: 0
  }
  #exif: Intervention\Image\Collection^ {#2339
    #items: array:2 [
      "FILE" => array:6 [
        "FileName" => "active_products.jpg"
        "FileDateTime" => 1663659322
        "FileSize" => 25082
        "FileType" => 2
        "MimeType" => "image/jpeg"
        "SectionsFound" => "IFD0"
      ]
      "COMPUTED" => array:5 [
        "html" => "width="553" height="185""
        "Height" => 185
        "Width" => 553
        "IsColor" => 1
        "ByteOrderMotorola" => 0
      ]
    ]
  }
} // app/Library/TransformImage.php:90

How to fix it ?

0

There are 0 best solutions below