Skip to content

PDF thumbnails to WEBP/AVIF #1766

Open
Open
@1ucay

Description

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

Metadata

Assignees

No one assigned

    Labels

    [Plugin] Modern Image FormatsIssues for the Modern Image Formats plugin (formerly WebP Uploads)[Type] EnhancementA suggestion for improvement of an existing feature

    Type

    No type

    Projects

    • Status

      Not Started/Backlog 📆

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions