image icon indicating copy to clipboard operation
image copied to clipboard

Fix a bug in ImagickDriver::pixelate that caused a DivideByZero excep…

Open psion-ar opened this issue 1 year ago • 0 comments

Hi there :)

Line 477 in ImagickDriver caused a DivideByZero exception.


   FAIL  Tests\Manipulations\PixelateTest
  ⨯ it can pixelate an image with dataset "imagick" / (0)                                                                                                                                   0.02s  
  ✓ it can pixelate an image with dataset "imagick" / (50)                                                                                                                                  0.16s  
  ✓ it can pixelate an image with dataset "imagick" / (100)                                                                                                                                 0.12s  
  ✓ it can pixelate an image with dataset "gd" / (0)                                                                                                                                        0.11s  
  ✓ it can pixelate an image with dataset "gd" / (50)                                                                                                                                       0.12s  
  ✓ it can pixelate an image with dataset "gd" / (100)                                                                                                                                      0.12s  
  ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────  
  FAILED  Tests\Manipulations\PixelateTest > it can pixelate an image with dataset "imagick" / (0)                                                                            DivisionByZeroError   
  Division by zero

  at src/Drivers/Imagick/ImagickDriver.php:477
    473▕         $width = $this->getWidth();
    474▕         $height = $this->getHeight();
    475▕ 
    476▕         foreach ($this->image as $image) {
  ➜ 477▕             $image->scaleImage(max(1, (int) ($width / $pixelate)), max(1, (int) ($height / $pixelate)));
    478▕             $image->scaleImage($width, $height);
    479▕         }
    480▕ 
    481▕         return $this;

  1   src/Drivers/Imagick/ImagickDriver.php:477
  2   src/Image.php:266


  Tests:    1 failed, 5 passed (5 assertions)
  Duration: 0.74s

I just wrapped the pixelate logic in a conditional, to run only when $pixelate !== 0.
The method signatures for all 3 "effect" methods that require argument values remain the same.
The tests are updated (BlurTest and SharpenTest too) to cover edge cases and to
stay consistent across the three method's i mentioned.

btw... <3

Regard's Alex

p.s. dont know why the rotation snapshots got updated. didnt mess with those

psion-ar avatar Jun 30 '24 11:06 psion-ar