Skip to content

Instantly share code, notes, and snippets.

@chriwo
Created June 11, 2017 16:08
Show Gist options
  • Save chriwo/0f6ab2ab66cc1387ce9e8dd0cc10208c to your computer and use it in GitHub Desktop.
Save chriwo/0f6ab2ab66cc1387ce9e8dd0cc10208c to your computer and use it in GitHub Desktop.
Image TypoScript library for adaptive images
lib.responsiveImage = IMAGE
lib.responsiveImage {
file {
import.current = 1
treatIdAsReference = 1
}
layoutKey = srcset
layout {
default {
element = <img src="###SRC###" width="###WIDTH###" height="###HEIGHT###" ###PARAMS### ###ALTPARAMS### ###BORDER### ###SELFCLOSINGTAGSLASH###>
source =
}
srcset {
element = <img src="###SRC###" srcset="###SOURCECOLLECTION###" ###PARAMS### ###ALTPARAMS### ###SELFCLOSINGTAGSLASH###>
source = |*|###SRC### ###SRCSETCANDIDATE###,|*|###SRC### ###SRCSETCANDIDATE###
}
picture {
element = <picture>###SOURCECOLLECTION###<img src="###SRC###" ###PARAMS### ###ALTPARAMS### ###SELFCLOSINGTAGSLASH###></picture>
source = <source src="###SRC###" media="###MEDIAQUERY###" ###SELFCLOSINGTAGSLASH###>
}
data {
element = <img src="###SRC###" ###SOURCECOLLECTION### ###PARAMS### ###ALTPARAMS### ###SELFCLOSINGTAGSLASH###>
source.noTrimWrap = | data-###DATAKEY###="###SRC###"|
}
}
sourceCollection {
# smartphone portrait
viewportXs {
srcsetCandidate = 320w
width = 300
mediaQuery = (min-device-width: 320px)
dataKey = xs
}
# tablet portrait
viewportSm {
srcsetCandidate = 768w
width = 500
mediaQuery = (min-device-width: 768px)
dataKey = sm
}
# small desktop, tablet landscape
viewportMd {
srcsetCandidate = 1024w
width = 700
mediaQuery = (min-device-width: 1024px)
dataKey = md
}
# large desktop
viewportLg {
srcsetCandidate = 1025w
width = 200
mediaQuery = (min-device-width: 1025px)
dataKey = lg
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment