Skip to content

Fix for Intervention Image v3 #197

@agskitkat

Description

@agskitkat

Thank you for your work. This is my favorite admin panel for Laravel. On the last project I noticed that $form->image() uses the second version of Intervention Image. I suggest a fix for switching to the third Intervention Image version in the file \src\Form\Field\Traits\ImageField.php:

  
  namespace OpenAdmin\Admin\Form\Field\Traits;
  
  use Illuminate\Support\Str;
  use Intervention\Image\Constraint;
  use Intervention\Image\Facades\Image as InterventionImage;
  use Intervention\Image\ImageManagerStatic;
  // Use class
  use Intervention\Image\ImageManager; 
  use Symfony\Component\HttpFoundation\File\UploadedFile;
  
  ...

  public function callInterventionMethods($target)
      {
          if (!empty($this->interventionCalls)) {
              // Add condition
              if(!class_exists(ImageManager::class)) {
                  $image = ImageManagerStatic::make($target);
              } else {
                  $driver = config("image.driver");
                  $manager = new ImageManager(new $driver());
                  $image = $manager->read($target);
              }
              foreach ($this->interventionCalls as $call) {
                  call_user_func_array(
                      [$image, $call['method']],
                      $call['arguments']
                  )->save($target);
              }
          }
  
          return $target;
      }

 ...

  public function __call($method, $arguments)
      {
          if (static::hasMacro($method)) {
              return $this;
          }
          // Change condition
          if (!class_exists(ImageManagerStatic::class) && !class_exists(ImageManager::class)) {
              throw new \Exception('To use image handling and manipulation, please install [intervention/image] first.');
          }
  
          $this->interventionCalls[] = [
              'method'    => $method,
              'arguments' => $arguments,
          ];
  
          return $this;
      }

As far as I can tell, the methods in version 3 are the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions