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

Refactor getPresetsByRatio #7

Merged
merged 2 commits into from
Oct 9, 2024
Merged

Refactor getPresetsByRatio #7

merged 2 commits into from
Oct 9, 2024

Conversation

Jade-GG
Copy link
Collaborator

@Jade-GG Jade-GG commented Oct 9, 2024

No description provided.

$presets = $presets->filter(fn ($preset, $key) => $key === 'placeholder' || $preset['w'] >= $preset['h']);
}
$vertical = $image->height() > $image->width();
$presets = $presets->filter(fn ($preset, $key) => $key === 'placeholder' || (($preset['h'] > $preset['w']) === $vertical));
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Could also write this check out fully, like:

$presets = $presets->filter(function ($preset, $key) use ($vertical) {
    if ($key === 'placeholder') {
        return true;
    }
    $presetVertical = $preset['h'] > $preset['w']);
    if ($presetVertical === $vertical) {
         return true;
    }
    return false;
});

Not sure if that's nicer.

@royduin
Copy link
Member

royduin commented Oct 9, 2024

Any info?

@Jade-GG
Copy link
Collaborator Author

Jade-GG commented Oct 9, 2024

Any info?

Nothing too specific, the working should stay exactly the same (aside from that this also fixes a possible edge case in the old code where the ratio is 0.9995 and it doesn't grab the right preset).

I happened to come across this code while looking at the source and found it very hard to read and written weirdly so I rewrote it :)

@royduin royduin merged commit bad34ae into justbetter:master Oct 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants