Skip to content
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

Metadata screenshot #621

Merged
merged 5 commits into from
May 10, 2024
Merged

Metadata screenshot #621

merged 5 commits into from
May 10, 2024

Conversation

pbking
Copy link
Contributor

@pbking pbking commented May 8, 2024

Add ability for user to manage the theme's screenshot from Editor on Metadata Modal.

Fixes: #560

image

To Test:

  • From the Editor open the CBT Metadata Editor Modal
  • Click "Replace" and choose another image to replace the screenshot with
  • Click "Update"

The image should be replaced in the theme folder and sized to 1200 x 900 px.

If a screenshot existed prior it should be removed. (Especially if the previous screenshot was another file type)

@pbking pbking marked this pull request as draft May 8, 2024 17:12
Comment on lines 208 to 217
public static function process_screenshot( $file_path ) {
$new_screeenshot_id = attachment_url_to_postid( $file_path );
$new_screenshot_metadata = wp_get_attachment_metadata( $new_screeenshot_id );
$upload_dir = wp_get_upload_dir();

$new_screenshot_location = path_join( $upload_dir['basedir'], $new_screenshot_metadata['file'] );

// TODO: We're not actually processing anything. The image might be of the wrong dimensions, too large, etc.
// We're just getting the file location so that we can copy it.
// Should we process it? Or just enforce that the screenshot is the correct size?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wondering if we should actually do any processing to the media selected (resize, compress, etc) or just use it as we get it and enforce sizes etc?

@pbking
Copy link
Contributor Author

pbking commented May 8, 2024

I removed the Remove button as I don't think that the screenshot should ever not be there.

@t-hamano
Copy link
Contributor

t-hamano commented May 9, 2024

@pbking Thank you for your quick implementation! I would like to test the backend a little more, but first I made some adjustments to the UI. What do you think? Are the buttons a little too noticeable?

Before After
no-screenshot-before no-screenshot-after
has-screenshot-before has-screenshot-after
admin/create-theme/theme-utils.php Outdated Show resolved Hide resolved
admin/create-theme/theme-utils.php Outdated Show resolved Hide resolved
admin/create-theme/theme-utils.php Outdated Show resolved Hide resolved
@pbking
Copy link
Contributor Author

pbking commented May 9, 2024

What do you think? Are the buttons a little too noticeable?

I think they are fine either way. I like the option you just pushed slightly better though.

👍

@pbking pbking marked this pull request as ready for review May 9, 2024 13:36
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

LGTM!

  • PHP error logs will not occur when adding a screenshot to a theme that does not originally have it.
  • The screenshot is resized appropriately
  • Also works on Windows host OS
@madhusudhand
Copy link
Contributor

It works great. I have observed one minor issue with image size.
Tried uploading following image

image-alignment-1200x4002-1

It previews screenshot differently.

image image

We should probably consider both ratio 4:3 and max size 1200x900 while resizing ?

@pbking
Copy link
Contributor Author

pbking commented May 10, 2024

Hrm 🤨

Regarding the wide image... The size restrictions are noted as a MAXIMUM of 1200 x 900. Which the image fits in. The original is less than 900 pixels tall. I believe that the cropping/resizing is acting as I would expect.

I tried another image that was very wide, but over 900 px tall (2500 x 1200) and it cropped and resized to the expected 1200 x 900 size.

There might be a better way to handle this edge case (upscaling the image maybe? then cropping it?) but I don't think it's worth the effort (when a user should really be providing an image of the appropriate dimensions anyway...)

If you believe that we should consider addressing that further would you mind opening an issue to explore additional solutions @madhusudhand ?

@pbking pbking merged commit 6273f02 into trunk May 10, 2024
2 checks passed
@pbking pbking deleted the metadata-screenshot branch May 10, 2024 12:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants