-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
ImageMagick Handler is extremely slow. #6149
Comments
Thank you for reporting. There seems to be a lot of waste. |
Here is a branch with the quickly updated code, I'm not sure how ready it is. It works for the standard crop/resize/fit, but the parts that add text/watermarks etc. |
Anyone had the time to look at the pull request from @colethorsen? |
@blurpy the config files allow you to build your own handlers, you can use this Gist to implement my updated handler without having to wait for the PR to be merged into the core. https://gist.github.com/colethorsen/9b90f8ef0443bc1f06452e203845ab02 |
@colethorsen thanks, yeah I've already gone that way. I need to strip exif, so basing it on your changes is much better to avoid calling imagemagick 3 times to resize, strip and save. |
I'm tackling on this now and there are some things I like to tidy up before submitting a PR. I'm targetting the
|
I think basically we should provide the same behavior as CI3. But the APIs are completely different already. |
The default values in PHP's GD functions are not 100. GDHandler's default is also 90. We should use the value.
|
Really great news that you have started to look at this! Would it be possible to add support for stripping exif while you are at it? I added this to my /**
* Strips exif from the image.
**
* @return ImageMagickHandler
*/
public function stripExif()
{
$this->addCommand(" -strip");
return $this;
} So now my code for resize looks like this: $resizeSuccess = $this->image->withFile($fullImagePath)
->resize($imageWidth, $imageHeight, true)
->stripExif()
->save($scaledImagePath, 70); Would be pretty nice if I could use the default handler in the future 🙂 |
PHP Version
7.4
CodeIgniter4 Version
4.2
CodeIgniter4 Installation Method
Composer (as dependency to an existing project)
Which operating systems have you tested for this bug?
macOS
Which server did you use?
apache
Database
MySQL 8
What happened?
Due to running commands multiple time through multiple exec calls and through unnecessarily setting the quality to 100 the implementation is greatly slowed down
Steps to Reproduce
The following code with a 712kb image is routinely taking over 14.5 seconds to execute.
Expected Output
The same image processed through ImageMagick using CodeIgniter 3 takes less than 2 seconds.
There are 2 primary differences. CodeIgniter 3 executes everything in one exec command instead of 2 in CodeIgnter 4, which brings up the second difference of when CodeIgniter 4 executes a command without a quality it sets it to 100.
Simply updating line 209 of the
ImageMagickHandler
from:to:
Increases performance to just over 6 seconds.
However, doing this and batching the requests together so one is made instead of 2 from:
to:
increases performance back to CodeIgniter 3 levels of around 2 seconds.
Anything else?
I've implemented a custom
ImageMagickHandler
that does this successfully for my specific use cases, however I'm not sure if there are other cases where waiting until save is called to execute a list of commands that have been compiled would be unwanted, in which case the implementation of image handlers as a whole might have to be reconsidered.i.e at the moment calling
$image->resize(2400, 16, true);
actually does something, where as in the case of my custom handler it just queues the command to be run when$image->save()
is called.The text was updated successfully, but these errors were encountered: