FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Change WP Image editor quality for mime types by mehulkaklotar · Pull Request #571 · WordPress/performance · GitHub

Change WP Image editor quality for mime types - #571

Merged
felixarntz merged 30 commits into
trunkfrom
enhancement/563-image-editor-quality
Nov 16, 2022
Merged

Change WP Image editor quality for mime types#571
felixarntz merged 30 commits into
trunkfrom
enhancement/563-image-editor-quality

Conversation

mehulkaklotar commented Nov 1, 2022
edited
Loading

Copy link
Copy Markdown
Member

Summary

Fixes #563

Relevant technical choices

For WP 6.1 below, all mime types for images, quality is set to 82
For WP 6.1+, all mime types for images should be default as per this ticket and PR and WebP to 82

Checklist

  • PR has either [Focus] or Infrastructure label.
  • PR has a [Type] label.
  • PR has a milestone or the no milestone label.

mehulkaklotar added [Type] Enhancement A suggestion for improvement of an existing feature [Focus] Images [Plugin] Modern Image Formats Issues for the Modern Image Formats plugin (formerly WebP Uploads) labels Nov 1, 2022
mehulkaklotar added this to the 1.7.0 milestone Nov 1, 2022
mehulkaklotar self-assigned this Nov 1, 2022
mehulkaklotar marked this pull request as ready for review November 8, 2022 14:41

felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@mehulkaklotar Unfortunately it looks like this PR does not address the issue correctly. Please see my comments below.

Comment thread modules/images/webp-uploads/load.php Outdated
Comment thread modules/images/webp-uploads/load.php Outdated
Comment thread modules/images/webp-uploads/load.php Outdated

mukeshpanchal27 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@mehulkaklotar Left some minor feedbacks

Comment thread modules/images/webp-uploads/load.php Outdated
Comment on lines +940 to +941
unlink( $file );
unset( $editor );

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Cleanup like this should happen in a tearDown method as it will not run if an assertion fails before it as part of the test body. These references can be stored in a property that is processed later in the tear down method. You might also consider splitting into separate test methods if such cleanup is needed before each "inner test".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why is this unsetting of variables even needed? They are just rewritten right below. It seems to me that these two lines could simply be removed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The unset for $file shouldn't be needed, but my guess regarding the $editor was to invoke \WP_Image_Editor_Imagick::__destruct or another classes' destructor. I'm not sure if this would be called immediately otherwise just by overwriting the variable. Again, I don't think it would be necessary with separate tests but if it were for some reason, it should get a comment to explain that, otherwise it doesn't make much sense 👍

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

unset was not required there. Unlink is still required for temporary file that is being generated with image editor save, but that is also needed at the end of test case. I have removed the in between unset and unlink code now.

felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@mehulkaklotar This looks good now in terms of production code. Left a few additional suggestions on wording and tests.

Comment thread modules/images/webp-uploads/load.php Outdated
Comment thread modules/images/webp-uploads/load.php Outdated
Comment thread modules/images/webp-uploads/load.php Outdated
Comment thread modules/images/webp-uploads/load.php Outdated
Comment thread modules/images/webp-uploads/load.php Outdated
Comment on lines +940 to +941
unlink( $file );
unset( $editor );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why is this unsetting of variables even needed? They are just rewritten right below. It seems to me that these two lines could simply be removed.

mehulkaklotar and others added 6 commits November 10, 2022 14:12
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>
Co-authored-by: Felix Arntz <felixarntz@users.noreply.github.com>

felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@mehulkaklotar Left a few follow up comments. Once these have been addressed, this should be good to go.

$this->assertSame( 82, $editor->get_quality(), 'Output image format is WebP. Quality setting for it should be 82 universally.' );

// Delete the temporary file.
unlink( $file );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This code will not run if any of the above assertion fails. See my comment above though, I think we should not use a temporary file anyway, so I think the code here should be removed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

see my comment above about test files.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@mehulkaklotar I understand now why you're using wp_tempnam(), that makes sense. However, the comment here still needs to be addressed: If an assertion fails, this line is never reached, which means it would leave the file in place.

We need to change this as follows:

  • Assign the results from any method calls from assertions here to variables (before the unlink call).
  • Run all assertions only after the unlink call.

This way, when an assertion fails, at least the file was still deleted as usual.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@felixarntz Another alternative could be to store the file name in a property and clean it up in a tear down.

Example class
class TestCase { // could also be implemented as a trait

	protected $to_unlink = [];
	
	public function test_something_with_a_file() {
		$filename = $this->temp_filename();
		
		file_put_contents( $filename, 'foobar' );
		
		// $filename will always be deleted after the test
	}

	protected function temp_filename() {
		$filename = wp_tempnam();

		$this->to_unlink[] = $filename;

		return $filename;
	}

	public function tear_down() {
		$this->to_unlink = array_filter(
			$this->to_unlink,
			function ( $filename ) {
				return unlink( $filename );
			}
		);
	}

}

felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@mehulkaklotar One last thing here, then this should be good to go.

$this->assertSame( 82, $editor->get_quality(), 'Output image format is WebP. Quality setting for it should be 82 universally.' );

// Delete the temporary file.
unlink( $file );

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@mehulkaklotar I understand now why you're using wp_tempnam(), that makes sense. However, the comment here still needs to be addressed: If an assertion fails, this line is never reached, which means it would leave the file in place.

We need to change this as follows:

  • Assign the results from any method calls from assertions here to variables (before the unlink call).
  • Run all assertions only after the unlink call.

This way, when an assertion fails, at least the file was still deleted as usual.

Copy link
Copy Markdown
Member Author

@felixarntz I have used the tear down method instead to unlink the file now. Please have a look.

mehulkaklotar requested review from felixarntz and removed request for aaemnnosttv November 16, 2022 11:14

felixarntz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@mehulkaklotar Thank you, LGTM!

adamsilverstein left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Nice work!

felixarntz merged commit c22ccfc into trunk Nov 16, 2022
felixarntz deleted the enhancement/563-image-editor-quality branch November 16, 2022 20:41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

None yet

Development

Successfully merging this pull request may close these issues.

Change default WebP quality to 82

6 participants


Back | FazBrowse Home | New Git URL