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

Using the imagick driver to crop and resize a png will create artifacts in the output #1426

Closed
mvveggel opened this issue Jan 30, 2025 · 3 comments · Fixed by #1428
Closed

Comments

@mvveggel
Copy link

Describe the bug

When using the Imagick driver to crop and resize an image the output contains artifacts, most noticeable in transparent areas (the transparent area is mostly black with random noise).
This does not happen in version <= 3.10.2
When either crop or resize is skipped the artifacts do not appear

Code Example

$imageManager = new \Intervention\Image\ImageManager(new \Intervention\Image\Drivers\Imagick\Driver());
$image = $imageManager->read('Sample.png');
$image->crop(2200, 1500);
$image->resize(220, 150);
$image->encodeByMediaType(null, 90);
$image->save('SampleCropped.png');

Expected behavior

The image is cropped and resized without adding artifacts

Images

Image
Image

Environment:

  • PHP Version: 8.3
  • OS: Linux (Ubuntu 22)
  • Intervention Image Version: 3.11.0
  • GD or Imagick: Imagick 6.9.11-60
@olivervogel
Copy link
Member

olivervogel commented Jan 30, 2025

Thanks for reporting. I will look into this.

Although I can confirm the error, there is a workaround here. I believe the same result can be achieved with the following call.

$imageManager = new \Intervention\Image\ImageManager(new \Intervention\Image\Drivers\Imagick\Driver());
$image = $imageManager->read('Sample.png');
$image->cover(220, 150);
$image->save('SampleCropped.png');

olivervogel added a commit that referenced this issue Jan 31, 2025
olivervogel added a commit that referenced this issue Feb 1, 2025
The CropModifier produced strange artifacts if another resize step was performed after the modification.

This patch removes the copying of the alpha channel in the CropModifier and implements a different method.

See: #1426
@olivervogel
Copy link
Member

This should work now with 3.11.1. However, I think it is better to use cover(), which is more efficient than your code from the example.

@mvveggel
Copy link
Author

mvveggel commented Feb 3, 2025

I can confirm it has been resolved in 3.11.1, cover seems to be a better way so I'll look into that thanks

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

Successfully merging a pull request may close this issue.

2 participants