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

PDFs causing failed queues #364

Closed
DynamiteGoesBoom opened this issue Dec 16, 2022 · 5 comments
Closed

PDFs causing failed queues #364

DynamiteGoesBoom opened this issue Dec 16, 2022 · 5 comments
Labels

Comments

@DynamiteGoesBoom
Copy link

DynamiteGoesBoom commented Dec 16, 2022

It appears that I/O is trying to optimize PDFs and when those fail/error-out the other optimizations don't run. I'm showing multiple failed "Optimizing images in X...."

Is there a way to skip PDFs? I know you added the Ignore SVGs/Gif option. Can we add PDFs to that as well? This would be handy as a global option in config/image-optimize.php or in the field settings.

Screenshots

Screenshot 2022-12-16 at 11 26 14 AM
Screenshot 2022-12-16 at 11 54 17 AM

Versions

  • Plugin version: ImageOptimize 4.0.3
  • Craft version: Craft CMS 4.3.5

Thanks for the help!

Additional Info

I just got this reply back from Matt @ Servd and I'm not sure if this helps:

Hey Mark. It looks like image magick bailed when attempting to create a placeholder image. It doesn't specify why exactly, just that it hit a Runtime Error.

I've seen that before with PNG files that have been optimised previously. ImageMagick has a bug where it explodes when it tries to process them.

It seems to be the first image in the open graph images volume that it got upset about but I'm not 100% sure what order ImageOptimize processes them in.

@DynamiteGoesBoom
Copy link
Author

Any updates or thoughts on this @khalwat? is skipping the PDFs an option that you could write in?

Thanks again!

@khalwat
Copy link
Contributor

khalwat commented Dec 21, 2022

Yes, I think adding an option to allow PDFs to be ignored is a good way forward, for setups where PDFs are not rendering properly due to Imagick failing as shown in your stack trace.

Probably it is running out of memory, due to complex or larger PDFs

@DynamiteGoesBoom
Copy link
Author

DynamiteGoesBoom commented Dec 21, 2022

@khalwat awesome and thanks! Yeah we're not really running into these issues on production as that's a much beefier server. But it would still be nice to be able to skip PDFs from being optimized.

I appreciate the response and will look for an update whenever you get to it.

Happy Holidays Andrew and thanks again!

I was certain that this would work:

{% set availableAt = craft.entries()
    .section('parkReservations')
    .relatedTo({
        targetElement: entry,
        field: 'availableAt.parkFieldSelect'
    })
.all() %}

@soulseekah
Copy link

This snippet lets you pick whether an optimize job gets queued or not depending on the extension. Works well for us.

Craft::$app->getQueue()->on(
    Queue::EVENT_BEFORE_PUSH,
    function(PushEvent $event): void {
        if (ResaveOptimizedImages::class !== $event->job::class) {
            return; // Do not intervene. Not the optimize job.
        }

        $asset = Asset::findOne($event->job->criteria);

        $unskippableExtensions = [
            'jpg', 'jpeg', 'png', 'bmp', 'gif', 'webp',
        ];

        if (in_array($asset->getExtension(), $unskippableExtensions, true)) {
            return; // All good. Let it through.
        }

        $event->handled = true; // Short-circuit to skip.
    }
);

@khalwat
Copy link
Contributor

khalwat commented Apr 2, 2024

Addressed via the above commits.

@khalwat khalwat closed this as completed Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants