imgix / js-core

A JavaScript client library for generating image URLs with imgix
https://www.imgix.com
BSD 2-Clause "Simplified" License
122 stars 20 forks source link

feat: dpr srcset options #307

Closed sylcastaing closed 2 years ago

sylcastaing commented 2 years ago

Description

This PR add 2 new options to control DPR srcset generation :

No breaking changes. buildSrcSet return the same as before if we don't provide this new options.

Checklist: New Feature

Steps to Test

targetDPRRatios

const client = new ImgixClient({
  domain: 'testing.imgix.net',
  secureURLToken: 'my-token',
  includeLibraryParam: false,
});

const srcset = client.buildSrcSet(
  'image.jpg',
  {
    h: 800,
    ar: '3:2',
    fit: 'crop',
  },
  {
    targetDPRRatios: [1, 2],
  },
);

Result :

https://testing.imgix.net/image.jpg?h=800&ar=3%3A2&fit=crop&dpr=1&s=3d754a157458402fd3e26977107ade74 1x,
https://testing.imgix.net/image.jpg?h=800&ar=3%3A2&fit=crop&dpr=2&s=a984ad1a81d24d9dd7d18195d5262c82 2x

targetDPRRatiosQualities

const client = new ImgixClient({
  domain: 'testing.imgix.net',
  includeLibraryParam: false,
});

const srcset = client.buildSrcSet(
  'image.jpg',
  { w: 100 },
  { targetDPRRatiosQualities: { 1: 45, 2: 30, 3: 20, 4: 15, 5: 10 } },
);

Result :

https://testing.imgix.net/image.jpg?w=100&dpr=1&q=45 1x,
https://testing.imgix.net/image.jpg?w=100&dpr=2&q=30 2x,
https://testing.imgix.net/image.jpg?w=100&dpr=3&q=20 3x,
https://testing.imgix.net/image.jpg?w=100&dpr=4&q=15 4x,
https://testing.imgix.net/image.jpg?w=100&dpr=5&q=10 5x
commit-lint[bot] commented 2 years ago

Features

Bug Fixes

Chore

Contributors

sylcastaing, frederickfogerty

Commit-Lint commands
You can trigger Commit-Lint actions by commenting on this PR: - `@Commit-Lint merge patch` will merge dependabot PR on "patch" versions (X.X.Y - Y change) - `@Commit-Lint merge minor` will merge dependabot PR on "minor" versions (X.Y.Y - Y change) - `@Commit-Lint merge major` will merge dependabot PR on "major" versions (Y.Y.Y - Y change) - `@Commit-Lint merge disable` will desactivate merge dependabot PR - `@Commit-Lint review` will approve dependabot PR - `@Commit-Lint stop review` will stop approve dependabot PR
frederickfogerty commented 2 years ago

@sylcastaing so I discussed with my team and we'd like to call the parameters devicePixelRatios instead of targetDPRs, and variableQualities rather than targetDPRRatiosQualities. This is the last change, and then we should be good to go!

sylcastaing commented 2 years ago

@sylcastaing so I discussed with my team and we'd like to call the parameters devicePixelRatios instead of targetDPRs, and variableQualities rather than targetDPRRatiosQualities. This is the last change, and then we should be good to go!

Ok thanks !

I have time tomorrow morning (Paris TZ) to make the last changes

frederickfogerty commented 2 years ago

Merci @sylcastaing, ca sonne bien ! À demain 👋

sylcastaing commented 2 years ago

I have push a new commit (not sure if the commit message is correct) with :