-
-
Notifications
You must be signed in to change notification settings - Fork 506
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
[BUG] Resized images look wrong #2986
Comments
Thanks for your report @rmens, this only seems to occur when you don't set the third parameter in resize: <img src="{{ post.thumbnail.src|resize(1200, 300, 'right') }}" /> leads to a correct image, although cropped from the right of the image. The error seems to lie in this logic: if (!$crop || $crop === 'default') {
return [
'x' => 0,
'y' => 0,
'src_w' => $src_w,
'src_h' => $src_h,
'target_w' => $w,
'target_h' => $h,
];
} https://github.com/timber/timber/blob/2.x/src/Image/Operation/Resize.php#L20 which has been changed from the 1.x version edit: removing This change was introduced in 18bf358 to fix integration tests from what I can see, |
Yes that works @Levdbas! It would be most logical to default to a center crop when a third parameter isn't specified. Alternatively, we could update the documentation to mandate a third parameter for resizing, although that may not be the most practical solution. |
To me, this sounds like a bug if it changed from how it used to be in v1. I would first fix the issue and then we could also discuss whether changing the default would make sense. But that would be a breaking change for which we have to provide the proper upgrade information. So, I’m wondering, rather than removing |
I’m wonder what the default behavior in 1.x was. That was probably center cropping and not top right cropping. |
$dest_ratio = $w / $h;
$src_wt = $src_h * $dest_ratio;
$src_ht = $src_w / $dest_ratio;
$src_x = $src_w / 2 - $src_wt / 2;
$src_y = ($src_h - $src_ht) / 6; Well this was the default behaviour in 1.x and should have also been de the default behavior in 2.x were it not for the shortcircuit bug that was introduced. What this exactly does however is kinda hard to wrap my head around :D This could use some documentation. Its is also kind of strange that you can pass a |
According to ChatGPT it's a center-ish crop
|
I remember that Jared once mentioned that the default crop is not fully from the top, but in the upper part of the image. This is a cropping area that works well in a lot of cases, and mostly works better than just a top or center crop. |
When I was still using 1.x without an off-site image resizer (which lead to not seeing this bug with the upgrade to 2.x of my theme) the crops always looked good. So cropping from the upper part of the image seems to be good choice imho. Documenting that behavior would be a win. |
Expected Behavior
Resized images to not look squashed or stretched.
Actual behavior
Resized images get squashed or stretched.
Steps to reproduce behavior
Notes
Also happens in a theme that's not the Timber starter theme. To rule out any user error, I tested with the starter theme.
What version of Timber are you using?
Timber 2.1.0
What version of WordPress are you using?
WordPress 6.5.2
What version of PHP are you using?
PHP 8.2
How did you install Timber?
Installed or updated Timber through Composer
The text was updated successfully, but these errors were encountered: