-
Notifications
You must be signed in to change notification settings - Fork 140
Change WP Image editor quality for mime types #571
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
Changes from 18 commits
75bf9d1
a2c34d0
52b8ede
59a3b4c
0ddc6d9
b4e342d
3625323
c3b625f
264ae36
80c5381
e05b4ec
0df8f1a
f4f022f
8cd2490
eeace67
929ba07
4af5bc9
039d484
07917e3
0d75cfb
8d3bcc7
7cfcd72
58b5e9b
af18717
7dd81d7
aab1208
0fb1e19
b1f3778
d3f97eb
f268b54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -775,6 +775,7 @@ public function it_should_create_webp_for_full_size_which_is_smaller_in_webp_for | |
| $this->opt_in_to_jpeg_and_webp(); | ||
|
|
||
| add_filter( 'webp_uploads_discard_larger_generated_images', '__return_true' ); | ||
| remove_all_filters( 'wp_editor_set_quality' ); | ||
mehulkaklotar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Look for an image that contains only full size mime type images. | ||
| $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' ); | ||
|
|
@@ -801,6 +802,7 @@ public function it_should_create_webp_for_some_sizes_which_are_smaller_in_webp_f | |
| $this->opt_in_to_jpeg_and_webp(); | ||
|
|
||
| add_filter( 'webp_uploads_discard_larger_generated_images', '__return_true' ); | ||
| remove_all_filters( 'wp_editor_set_quality' ); | ||
mehulkaklotar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Look for an image that contains all of the additional mime type images. | ||
| $attachment_id = self::factory()->attachment->create_upload_object( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/balloons.webp' ); | ||
|
|
@@ -918,6 +920,41 @@ public function it_should_create_mime_types_for_allowed_sizes_only_via_global_va | |
| $this->assertImageNotHasSizeSource( $attachment_id, 'not_allowed_size_200x150', 'image/webp' ); | ||
| } | ||
|
|
||
| /** | ||
| * Test image quality for image conversion. | ||
| * | ||
| * @test | ||
| */ | ||
| public function it_should_set_quality_with_image_conversion() { | ||
felixarntz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $editor = wp_get_image_editor( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/dice.png', array( 'mime_type' => 'image/png' ) ); | ||
|
|
||
| // Quality setting for the source image. For PNG the fallback default of 82 is used. | ||
| $this->assertSame( 82, $editor->get_quality(), 'Default quality setting for PNG is 82.' ); | ||
|
|
||
| $file = wp_tempnam(); | ||
felixarntz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // A PNG image will be converted to WebP whose quality should be 82 universally. | ||
| $editor->save( $file, 'image/webp' ); | ||
felixarntz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->assertSame( 82, $editor->get_quality(), 'Output image format is WebP. Quality setting for it should be 82 universally.' ); | ||
|
|
||
| unlink( $file ); | ||
| unset( $editor ); | ||
|
||
|
|
||
| $editor = wp_get_image_editor( TESTS_PLUGIN_DIR . '/tests/testdata/modules/images/leafs.jpg' ); | ||
|
|
||
| // Quality setting for the source image. For JPG the fallback default of 82 is used. | ||
| $this->assertSame( 82, $editor->get_quality(), 'Default quality setting for JPG is 82.' ); | ||
|
|
||
| $file = wp_tempnam(); | ||
|
|
||
| // A JPG image will be converted to WebP whose quality should be 82 universally. | ||
| $editor->save( $file, 'image/webp' ); | ||
felixarntz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->assertSame( 82, $editor->get_quality(), 'Output image format is WebP. Quality setting for it should be 82 universally.' ); | ||
|
|
||
| unlink( $file ); | ||
|
||
| unset( $editor ); | ||
| } | ||
felixarntz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Runs (empty) hooks to satisfy webp_uploads_in_frontend_body() conditions. | ||
| */ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.