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

PDF thumbnails to WEBP/AVIF #1766

Open
1ucay opened this issue Dec 20, 2024 · 3 comments
Open

PDF thumbnails to WEBP/AVIF #1766

1ucay opened this issue Dec 20, 2024 · 3 comments
Labels
[Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Type] Enhancement A suggestion for improvement of an existing feature

Comments

@1ucay
Copy link

1ucay commented Dec 20, 2024

Dear all,

if you upload PDF, in metadata sizes we have array with jpgs.

I tried fix with

add_filter( 'webp_uploads_upload_image_mime_transforms', 'core_webp_uploads_upload_image_mime_transforms', 9, 2 );
function core_webp_uploads_upload_image_mime_transforms( $default_transforms ) {

    $mimes = wp_get_mime_types();

    $output_format = webp_uploads_mime_type_supported( 'image/avif' ) ? webp_uploads_get_image_output_format() : 'webp';
    $transforms    = webp_uploads_is_fallback_enabled() ? array( 'image/jpeg', 'image/' . $output_format ) : array( 'image/' . $output_format );

    foreach( $mimes as $k => $v ) {
        if ( ! isset( $default_transforms[ $v ] ) )
            $default_transforms[ $v ] = $transforms;
    }

    return $default_transforms;
}

If you upload PSD with mime image/vnd.adobe.photoshop and genereate sizes with some custom code (imagemagick support PSD) like PDF does

add_filter( 'wp_generate_attachment_metadata', 'core_wp_generate_attachment_metadata', 9, 2 );

it working ok. I have nice jpg and avif in metadata.

But, different situation is with PDF mime application/pdf. It is blocked by helper.php line 145

$image_path = wp_get_original_image_path( $attachment_id );

and inside function is condition

  if ( ! wp_attachment_is_image( $attachment_id ) ) {

We dont have any filter skip this check, so PDF avif is not working. Best would be add filter to "wp_attachment_is" and override.

Im working on LibreOffice (exec soffice), audiowave (exec https://github.com/bbc/audiowaveform ) , PSD / AI (imagemagick) thumbnailer.
https://core.trac.wordpress.org/ticket/62712

@github-project-automation github-project-automation bot moved this to Not Started/Backlog 📆 in WP Performance 2024 Dec 20, 2024
@westonruter westonruter added the [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) label Dec 20, 2024
@swissspidy swissspidy added the [Type] Enhancement A suggestion for improvement of an existing feature label Jan 14, 2025
@AhmarZaidi
Copy link
Contributor

Hey @1ucay

If I understand correctly, the issue is that PDF uploads should generate previews, but generation is blocked because wp_get_original_image_path() checks wp_attachment_is_image(), which returns false for PDFs.

I did try to replicate the issue and did not get pdf previews but I was unable to confirm if that is due to ! wp_attachment_is_image( $attachment_id ).

If you could revisit the issue once more and provide replication instructions, it would be very helpful.

@1ucay
Copy link
Author

1ucay commented Feb 8, 2025

Dear @AhmarZaidi
yes, exactly, for AVIF previews it is blocked by wp_attachment_is_image, if mime type of file is not image/
Would be possible add some apply_filters?

@1ucay
Copy link
Author

1ucay commented Feb 8, 2025

you can add application/pdf over webp_uploads_upload_image_mime_transforms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) [Type] Enhancement A suggestion for improvement of an existing feature
Projects
Status: Not Started/Backlog 📆
Development

No branches or pull requests

4 participants