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

Plugin: Images - maxWidth not being respected in largest() function #138

Open
TotalLag opened this issue Dec 7, 2021 · 3 comments
Open

Comments

@TotalLag
Copy link

TotalLag commented Dec 7, 2021

I have the following widths configured:

widths: [1800, 1200, 900, 600, 350]

On an image with original width 1500 and using the following code for src: helpers.images.largest('/images/photo-2.jpg',{maxWidth:400}).relative

Expected:
return value of photo-2-ejs-350.jpg

Actual:
return value of photo-2-ejs-1200.jpg

I have deleted my manifest and regenerated to no avail.

@TotalLag TotalLag changed the title maxWidth not being respected in largest() function Plugin: Images - maxWidth not being respected in largest() function Dec 7, 2021
@dmitrysmagin
Copy link

Here's the fix for the issue:

--- a/node_modules/@elderjs/plugin-images/utils/helpers.js
+++ b/node_modules/@elderjs/plugin-images/utils/helpers.js
@@ -58,6 +58,7 @@ function getLargest(fileSizes, orgFormat, maxWidth) {
     .filter((p) => p.format === orgFormat)
     .find((p, i, arr) => {
       let largest = true;
+      if (p.width > maxWidth) return false;
       arr.forEach((a) => {
         if (a.width > maxWidth) return;
         if (a.width > p.width) largest = false;

@TotalLag
Copy link
Author

TotalLag commented Jul 14, 2022

TY this is great. I'll test this out and if a PR doesn't already exist, can create one.

EDIT: Looks like you already did! 😃

nickreese added a commit that referenced this issue Jul 14, 2022
@nickreese
Copy link
Contributor

This will be picked up on the typescript branch release. I'm trying to release beta 1.8.0-beta.3 for Elder.js and betas for all of the plugins tonight.

We've got ElderGuide.com migrated over, we'll get FindEnergy.com and the others moved then release 1.8.0 and a migration guide.

Included here: 52354e2

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

No branches or pull requests

3 participants