-
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 1 commit
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
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -926,32 +926,33 @@ public function it_should_create_mime_types_for_allowed_sizes_only_via_global_va | |
| * @test | ||
| */ | ||
| public function it_should_set_quality_with_image_conversion() { | ||
| global $wp_version; | ||
| // Set conversions for uploaded images. | ||
| add_filter( 'image_editor_output_format', array( $this, 'image_editor_output_formats' ) ); | ||
|
|
||
| $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(); | ||
| $this->assertSame( 82, $editor->get_quality(), 'Output image format is WEBP. Quality setting for it 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.' ); | ||
|
|
||
| // A JPG image will be converted to WEBP whose quality should be 82 universally. | ||
| $editor->save(); | ||
| $this->assertSame( 82, $editor->get_quality(), 'Output image format is WEBP. Quality setting for it should be 82 universally.' ); | ||
| $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 ); | ||
| remove_filter( 'image_editor_output_format', array( $this, 'image_editor_output_formats' ) ); | ||
| } | ||
felixarntz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
|
|
@@ -961,18 +962,4 @@ private function mock_frontend_body_hooks() { | |
| remove_all_actions( 'template_redirect' ); | ||
| do_action( 'template_redirect' ); | ||
| } | ||
|
|
||
| /** | ||
| * Changes the output format when editing images. PNG and JPEG files | ||
| * will be converted to WEBP (if the image editor in PHP supports it). | ||
| * | ||
| * @param array $formats Output formats. | ||
| * | ||
| * @return array | ||
| */ | ||
| public function image_editor_output_formats( $formats ) { | ||
| $formats['image/png'] = 'image/webp'; | ||
| $formats['image/jpeg'] = 'image/webp'; | ||
| return $formats; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.