Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions plugins/webp-uploads/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ function webp_uploads_get_upload_image_mime_transforms(): array {
$output_format = webp_uploads_mime_type_supported( 'image/avif' ) ? webp_uploads_get_image_output_format() : 'webp';

$default_transforms = array(
'image/jpeg' => array( 'image/' . $output_format ),
'image/webp' => array( 'image/' . $output_format ),
'image/avif' => array( 'image/avif' ),
'image/png' => array( 'image/' . $output_format ),
'image/jpeg' => array( 'image/' . $output_format ),
'image/webp' => array( 'image/' . $output_format ),
'image/avif' => array( 'image/avif' ),
'image/png' => array( 'image/' . $output_format ),
'application/pdf' => array( 'image/' . $output_format ),
);

// Check setting for whether to generate both JPEG and the modern output format.
Expand Down Expand Up @@ -144,7 +145,11 @@ function webp_uploads_generate_additional_image_source( int $attachment_id, stri
return new WP_Error( 'image_mime_type_not_supported', __( 'The provided mime type is not supported.', 'webp-uploads' ) );
}

$image_path = wp_get_original_image_path( $attachment_id );
if ( wp_attachment_is_image( $attachment_id ) ) {
$image_path = wp_get_original_image_path( $attachment_id );
} else {
$image_path = get_attached_file( $attachment_id );
}
if ( false === $image_path || ! file_exists( $image_path ) ) {
return new WP_Error( 'original_image_file_not_found', __( 'The original image file does not exists, subsizes are created out of the original image.', 'webp-uploads' ) );
}
Expand Down
28 changes: 20 additions & 8 deletions plugins/webp-uploads/tests/test-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -414,17 +414,19 @@ public function test_it_should_return_default_transforms_when_filter_returns_non
if ( webp_uploads_mime_type_supported( 'image/avif' ) ) {
$this->set_image_output_type( 'avif' );
$default_transforms = array(
'image/jpeg' => array( 'image/avif' ),
'image/webp' => array( 'image/avif' ),
'image/avif' => array( 'image/avif' ),
'image/png' => array( 'image/avif' ),
'image/jpeg' => array( 'image/avif' ),
'image/webp' => array( 'image/avif' ),
'image/avif' => array( 'image/avif' ),
'image/png' => array( 'image/avif' ),
'application/pdf' => array( 'image/avif' ),
);
} else {
$default_transforms = array(
'image/jpeg' => array( 'image/webp' ),
'image/webp' => array( 'image/webp' ),
'image/avif' => array( 'image/avif' ),
'image/png' => array( 'image/webp' ),
'image/jpeg' => array( 'image/webp' ),
'image/webp' => array( 'image/webp' ),
'image/avif' => array( 'image/avif' ),
'image/png' => array( 'image/webp' ),
'application/pdf' => array( 'image/webp' ),
);
}

Expand Down Expand Up @@ -500,6 +502,16 @@ public function test_it_should_return_jpeg_and_webp_transforms_when_option_gener
}
}

/**
* Returns true if 'application/pdf' is included in the MIME transforms array.
*/
public function test_it_should_include_pdf_in_mime_transforms(): void {
$transforms = webp_uploads_get_upload_image_mime_transforms();

$this->assertArrayHasKey( 'application/pdf', $transforms );
$this->assertContains( 'image/webp', $transforms['application/pdf'] );
}

/**
* @dataProvider data_provider_image_filesize
*
Expand Down
Loading