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

feat: add ability to pass in custom widths #55

Merged
merged 7 commits into from
Nov 8, 2019
Merged

Conversation

sherwinski
Copy link
Contributor

@sherwinski sherwinski commented Nov 7, 2019

This PR adds logic that allows users to pass in a custom widths list when generating srcset pairs.
In certain cases when users know exactly what widths they want to have their images rendered at, they will be able to pass in an array of integers into the widths: keyword parameter.
See the following example:

@client ||= Imgix::Client.new(host: 'testing.imgix.net', include_library_param: false)
.path('image.jpg')
.to_srcset(widths: [100, 500, 1000, 1800])

Will generate the following srcset of width-pairs:

https://testing.imgix.net/image.jpg?w=100 100w,
https://testing.imgix.net/image.jpg?w=500 500w,
https://testing.imgix.net/image.jpg?w=1000 1000w,
https://testing.imgix.net/image.jpg?w=1800 1800w

Please note that in situations where a srcset is being rendered as a fixed image, any custom widths passed in will be ignored. Additionally, if both widths and a width_tolerance are passed in to the to_srcset method, the custom widths list will take precedence.

@sherwinski sherwinski requested a review from jayeb November 7, 2019 00:01
@sherwinski sherwinski changed the title feat: add ability to pass in custom sizes feat: add ability to pass in custom widths Nov 7, 2019
@sherwinski sherwinski merged commit 6b79413 into master Nov 8, 2019
@sherwinski sherwinski deleted the srcset-custom-sizes branch November 8, 2019 19:33
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.

2 participants