-
Notifications
You must be signed in to change notification settings - Fork 19
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: custom srcset #55
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍, just one syntax question before we merge:
src/Imgix/UrlBuilder.php
Outdated
@@ -65,65 +74,96 @@ public function createURL($path, $params=array()) { | |||
return $uh->getURL(); | |||
} | |||
|
|||
public function createSrcSet($path, $params=array()) { | |||
public function createSrcSet($path, $params=array(), $start=100, $stop=8192, $tol=8, $disable_variable_quality=false) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have disable_variable_quality
written in camelCase? [1]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! Yes! It should be disableVariableQuality
, thank you! I will make this change right now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I have updated and camel-cased the flag: disableVariableQuality
This PR introduces custom srcsets. Target widths functionality has been
extended to support
$start
,$stop
, and$tol
. These values definewhere the array of target widths start, stop, and how much variation
is tolerated between each subsequent width.
This functionality is accessed via the
createSrcSet
function whichhas also been extended to support the above functionality.
Now when source set pairs are constructed they are constructed either
with default target widths or by a custom target widths array generated
if
$start
,$stop
, and/or$tol
deviates from the defaults.This PR aims to test the new functionality in a simple manner. By
leveraging php's string literal conventions, integration tests are
performed on the entire output
srcset
string. I chose this routeto keep the tests easy to reason about (i.e. tried to avoid complicated
setup and string/array manipulation).
Food for thought, we discussed whether we should impl this feature
with default arguments or by passing an
options=array()
. I've chosento move ahead with default args, but am happy to impl another solution.
I could also add some constants here, namely for
8192
,100
, butI figured this could be done if/when
$INCREMENT_PERCENTAGE
isnormalized to
$SRCSET_WIDTH_TOLERANCE
.