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

Support custom image size variations #24

Closed
olemarius opened this issue Mar 4, 2014 · 1 comment
Closed

Support custom image size variations #24

olemarius opened this issue Mar 4, 2014 · 1 comment

Comments

@olemarius
Copy link

When using height parameter and cropping I experienced some problems with the data.requestedWidth being set to nearest multiple of 160. The actual size of the image would be 800, but it's scaled down using max-width:100%; in css. This affects the height, and result in the image not filling it's static width/height container perfectly.

I solved this by adding s.defaultWidths which will be an array of the widths, and if the data.requestedWidth does not match, it use the 160 rule.

// Added custom widths
if (s.defaultWidths) {
    if (s.defaultWidths.indexOf(data.requestedWidth) === -1) {
        //Minimize variants for caching improvements; round up to nearest multiple of 160
        data.requestedWidth = data.requestedWidth - (data.requestedWidth % 160) + 160; //Will limit to 13 variations
    }
}

Usage:

<script>
    window.slimmage = {
        defaultWidths: [226,468,710,952]
    };
</script>

Didnt think about it before now, but maybe widthVariants would be better name.

@lilith
Copy link
Member

lilith commented Jan 6, 2015

This turned out to be a rounding bug, and is fixed in 0.2.4. 800-pixel wide elements now cause 800-pixel wide images to be requested.

If you want to whitelist additional sizes that are not multiples of stepWidth (160), you can do that via window.slimmage.adjustImageParameters.

Example:

window.slimmage = {
   adjustImageParameters: function(data){
      var idealSize = data.width * data.dpr;
      if ([226,468,710,952].indexOf(idealSize) !== -1){
         data.requestedWidth = idealSize;
      }
   }
}

@lilith lilith closed this as completed Jan 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants