Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Intervention Image v3 #197

Open
agskitkat opened this issue Dec 6, 2024 · 0 comments
Open

Fix for Intervention Image v3 #197

agskitkat opened this issue Dec 6, 2024 · 0 comments

Comments

@agskitkat
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant