Skip to content

feat: rewrite ImageMagickHandler to rely solely on the PHP imagick extension #9526

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

Merged
merged 2 commits into from
Apr 22, 2025

Conversation

michalsn
Copy link
Member

Description
This PR rewrites ImageMagickHandler to rely solely on the PHP imagick extension.

Since we required this extension from the beginning, there should be no problems for users.

Fixes #9512

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn michalsn added enhancement PRs that improve existing functionalities 4.7 labels Apr 16, 2025
@michalsn michalsn linked an issue Apr 17, 2025 that may be closed by this pull request
@paulbalandan
Copy link
Member

Would this fix #6149 ? Or performance is still somehow the same?

@michalsn
Copy link
Member Author

Yes, it should be better. Using the imagick extension can actually be faster than CLI in many cases because we load and manipulate images entirely in memory.

This may not be true only for very large files.

It would be great if someone with a real-world use case could check this out.

@michalsn
Copy link
Member Author

I ran some tests with a PNG image that was 6.7 MB in size.

$iterator = new \CodeIgniter\Debug\Iterator();
$iterator->add('imagick', static function () {
    service('image', 'imagick')
        ->withFile(WRITEPATH . '/test/mypic.png')
        ->flip()
        ->resize(500, 500, true)
        ->text('Copyright 2025 My Photo Co', [
            'color' => '#fff',
            'opacity' => 0.5,
            'withShadow' => true,
            'hAlign' => 'center',
            'vAlign' => 'bottom',
            'fontSize' => 20,
            'padding' => 20,
        ])
        ->save(WRITEPATH . '/test/image.jpg');
});

return $iterator->run(10);
Version Time (seconds)
Old version 79.5258
New version 1.8617

@michalsn michalsn linked an issue Apr 19, 2025 that may be closed by this pull request
@github-actions github-actions bot added the stale Pull requests with conflicts label Apr 20, 2025
@michalsn michalsn force-pushed the feat/imagick-rewrite branch from 6b1884a to 935b734 Compare April 22, 2025 06:24
@michalsn michalsn force-pushed the feat/imagick-rewrite branch from 935b734 to 7ae3d42 Compare April 22, 2025 06:28
@michalsn michalsn removed the stale Pull requests with conflicts label Apr 22, 2025
@codeigniter4 codeigniter4 deleted a comment from github-actions bot Apr 22, 2025
@michalsn
Copy link
Member Author

Thank you for the review @paulbalandan, and everyone else for the feedback.

@michalsn michalsn merged commit e15078c into codeigniter4:4.7 Apr 22, 2025
50 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.7 enhancement PRs that improve existing functionalities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: New version Imagick not supported (deprecated) ImageMagick Handler is extremely slow.
3 participants