Skip to content

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

Merged
michalsn merged 2 commits into
codeigniter4:4.7from
michalsn:feat/imagick-rewrite
Apr 22, 2025
Merged

feat: rewrite ImageMagickHandler to rely solely on the PHP imagick extension#9526
michalsn merged 2 commits into
codeigniter4:4.7from
michalsn:feat/imagick-rewrite

Conversation

@michalsn

Copy link
Copy Markdown
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

@michalsnmichalsn added enhancement PRs that improve existing functionalities 4.7 labels Apr 16, 2025
@michalsnmichalsn linked an issue Apr 17, 2025 that may be closed by this pull request
Comment threadsystem/Images/Handlers/ImageMagickHandler.php Outdated
Comment threadutils/phpstan-baseline/method.childReturnType.neon Outdated
Comment threadutils/phpstan-baseline/method.childReturnType.neon Outdated
@paulbalandan

Copy link
Copy Markdown
Member

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

@michalsn

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
MemberAuthor

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

$iterator = new \CodeIgniter\Debug\Iterator();
$iterator->add('imagick', staticfunction () {
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);
VersionTime (seconds)
Old version79.5258
New version1.8617

@michalsnmichalsn linked an issue Apr 19, 2025 that may be closed by this pull request
@github-actionsgithub-actionsBot added the stale Pull requests with conflicts label Apr 20, 2025
@michalsn
michalsnforce-pushed the feat/imagick-rewrite branch from 6b1884a to 935b734CompareApril 22, 2025 06:24
michalsnand others added 2 commits April 22, 2025 08:27
Co-authored-by: John Paul E. Balandan, CPA <paulbalandan@gmail.com>
@michalsn
michalsnforce-pushed the feat/imagick-rewrite branch from 935b734 to 7ae3d42CompareApril 22, 2025 06:28
@michalsnmichalsn removed the stale Pull requests with conflicts label Apr 22, 2025
@codeigniter4codeigniter4 deleted a comment from github-actionsBotApr 22, 2025
@michalsn

Copy link
Copy Markdown
MemberAuthor

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

@ddevsr

Copy link
Copy Markdown
Collaborator

Btw, missing required ext-imagick in composer?

@samsonasik

Copy link
Copy Markdown
Member

@ddevsr that already on "suggest" section

"ext-imagick": "If you use Image class ImageMagickHandler",

should be only when using the handler, if not, it not required.

@michalsn
michalsn deleted the feat/imagick-rewrite branch May 8, 2025 18:48
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancementPRs 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.

4 participants

@michalsn@paulbalandan@ddevsr@samsonasik