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

Don't resize image if the full version already has the expected height/width #323

Open
1 task done
ocean90 opened this issue Jan 7, 2025 · 0 comments · May be fixed by #324
Open
1 task done

Don't resize image if the full version already has the expected height/width #323

ocean90 opened this issue Jan 7, 2025 · 0 comments · May be fixed by #324
Assignees
Milestone

Comments

@ocean90
Copy link
Contributor

ocean90 commented Jan 7, 2025

Is your enhancement related to a problem? Please describe.

// generate the new size
$editor = wp_get_image_editor( $avatar_full_path );
if ( ! is_wp_error( $editor ) ) {
$resized = $editor->resize( $size, $size, true );
if ( ! is_wp_error( $resized ) ) {
$dest_file = $editor->generate_filename();
$saved = $editor->save( $dest_file );
if ( ! is_wp_error( $saved ) ) {
// Transform the destination file path into URL.
$dest_file_url = '';
if ( false !== strpos( $dest_file, $upload_path['basedir'] ) ) {
$dest_file_url = str_replace( $upload_path['basedir'], $upload_path['baseurl'], $dest_file );
} elseif ( is_multisite() && false !== strpos( $dest_file, ABSPATH . 'wp-content/uploads' ) ) {
$dest_file_url = str_replace( ABSPATH . 'wp-content/uploads', network_site_url( '/wp-content/uploads' ), $dest_file );
}
$local_avatars[ $size ] = $dest_file_url;
}
}
}

If the image is 160x160 and an avatar for 160x160px is requested another image with the suffix -160x160 is generated. I think we can just use the full image as set in

$local_avatars[ $size ] = $local_avatars['full']; // just in case of failure elsewhere

We can use $editor->get_size() to compare the size of image with the requested size.

Designs

No response

Describe alternatives you've considered

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@ocean90 ocean90 added the type:enhancement New feature or request. label Jan 7, 2025
@jeffpaul jeffpaul added this to the Future Release milestone Jan 7, 2025
@jeffpaul jeffpaul added help wanted and removed type:enhancement New feature or request. labels Jan 7, 2025
@ocean90 ocean90 linked a pull request Jan 7, 2025 that will close this issue
4 tasks
@jeffpaul jeffpaul moved this from To Do to Code Review in Open Source Practice Jan 7, 2025
@jeffpaul jeffpaul modified the milestones: Future Release, 2.9.0 Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Code Review
Development

Successfully merging a pull request may close this issue.

3 participants