sizing up responsive images - drupalcon · 2016. 1. 28. · use responsive images in older...

115
MARC DRUMMOND TALK DATE SPEAKER JUNE 26, 2015 SIZING UP RESPONSIVE IMAGES MAKE A PLAN BEFORE YOU DRUPAL Photo credit: Dave Emerson, “Trouble”, Flickr Creative Commons

Upload: others

Post on 19-Aug-2020

10 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

MARC DRUMMOND

TALK

DATE SPEAKERJUNE 26, 2015

SIZING UP RESPONSIVE IMAGESMAKE A PLAN BEFORE YOU DRUPAL

Photo credit: Dave Emerson, “Trouble”, Flickr Creative Commons

Page 2: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Dave Emerson, “Trouble”, Flickr Creative Commons

Marc Drummond

@MarcDrummond

mdrummondIRC, drupal.org

marcdrummond.com

Front-end Developer, Lullabot

Page 3: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

CERN, WE HAVE A PROBLEMAND IT INVOLVES CATS

Page 4: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Mr Thinktank, “SDC19276”, Flickr Creative Commons

Page 5: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Doug Woods, “Midge Our Cute New Kitten Cat”, Flickr Creative Commons

Page 6: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: [paumelia], “so happy smiling cat”, Flickr Creative Commons

Page 7: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Pete Teoh, “Aston Loves Andy”, Flickr Creative Commons

Page 8: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Doug Woods, “Midge Our Cute New Kitten Cat”, Flickr Creative Commons

Page 9: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Doug Woods, “Midge Our Cute New Kitten Cat”, Flickr Creative Commons

Page 10: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Doug Woods, “Midge Our Cute New Kitten Cat”, Flickr Creative Commons

Page 11: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Doug Woods, “Midge Our Cute New Kitten Cat”, Flickr Creative Commons

Page 12: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Guyon Moree, “Angry Tiger”, Flickr Creative Commons

Page 13: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Doug Woods, “Midge Our Cute New Kitten Cat”, Flickr Creative Commons

Page 14: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: [paumelia], “so happy smiling cat”, Flickr Creative Commons

Page 15: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Mr Thinktank, “SDC19276”, Flickr Creative Commons

Page 16: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Doug Woods, “Midge Our Cute New Kitten Cat”, Flickr Creative Commons

Page 17: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Guyon Moree, “Angry Tiger”, Flickr Creative Commons

Page 18: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SMALL SCREEN LARGE SCREEN

SMALL PHOTO

LARGE PHOTO

Page 19: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Tina Lawson, “Heidi”, Flickr Creative Commons

What if we…… provide different image files…

… for different screen sizes?

Woh.

Page 20: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Gonzolo G Useta, “La Ultima Vida”, Flickr Creative Commons

… browsers are fastExcept…

Page 21: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Tina Lawson, “Heidi”, Flickr Creative Commons

What if we…… give browsers layout info…

… in our HTML?

Woh.

Page 22: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint
Page 23: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

<picture>      <source  media="(min-­‐width:  40em)"          srcset="big.jpg  1x,  big-­‐hd.jpg  2x">      <source            srcset="small.jpg  1x,  small-­‐hd.jpg  2x">      <img  src="fallback.jpg"  alt="">  </picture>

PICTURE ELEMENT

Page 24: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

ART DIRECTIONDIFFERENT IMAGE CROPS PER MEDIA QUERY

Page 25: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

ART DIRECTIONDIFFERENT ASPECT RATIOS PER MEDIA QUERY

Page 26: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

IMAGE TYPES.WEBP CAN FALLBACK TO .JPG

Page 27: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

<img  src="small.jpg"            srcset="large.jpg  1024w,                              medium.jpg  640w,                              small.jpg  320w"            sizes="(min-­‐width:  36em)  33.3vw,                          100vw"            alt="A  rad  wolf">

SIZES + SRCSET ATTRIBUTES

Page 28: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

PICTUREFILLUSE RESPONSIVE IMAGES IN OLDER BROWSERS

Page 29: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

DRUPAL 7PICTURE AND BREAKPOINTS MODULES

Page 30: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

DRUPAL 8RESPONSIVE IMAGE AND BREAKPOINT MODULES (IN CORE!)

Page 31: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

LET’S MAKE A PLAN.

Page 32: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

RESPONSIVE LAYOUTS ARE FLUIDIMAGE FILES ARE NOT

Photo credit: CelloPics, “Cat Only Loves Fresh Water”, Flickr Creative Commons

Page 33: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

TARGET / CONTEXT = RESULTWIDTH %

Page 34: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

RASTER IMAGESMEASURED IN PX, NOT %

Page 35: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

ANALYZEHOW DOES THIS TYPE OF IMAGE FIT INTO THE SITE LAYOUT?

Photo credit: Jenny Lee Silver, “Photo A Day: June 2006”, Flickr Creative Commons

Page 36: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Tiger sunbathing in a boxI am unable to envision anything quite as adorable as my cat Tiger lounging in the sun, cuddled in his precious little box.

He has been a fan of this box since he was just a kitten, and we have preserved it ever since. When Tiger was just nine months old, we almost threw out this little half box. He mauled a couch that day. The next day, we brought in the box from the recycling, and he has been a happy cat ever since.

I have taken many photos over the years of Tiger cuddled in this box, but I love how the light looks in this particular picture.

You can feel the warmth of the sun, Tiger purring, and envision him slowly closing his eyes and yawning. There are few moments more tender than those of a sunbathing cat.

Tiger cuddles in his box, basking in the sun.

Photo credits: Clare, “I Am Not Too Big For This Box” and “Does This Box Make Me Look Fat?”, Flickr Creative Commons

Page 37: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Tiger sunbathing in a boxI am unable to envision anything quite as adorable as my cat Tiger lounging in the sun, cuddled in his precious little box.

He has been a fan of this box since he was just a kitten, and we have preserved it ever since. When Tiger was just nine months old, we almost threw out this little half box. He mauled a couch that day. The next day, we brought in the box from the recycling, and he has been a happy cat ever

Page 38: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

this box, but I love how the light looks in this particular picture.

You can feel the warmth of the sun, Tiger purring, and envision him slowly closing his eyes and yawning. There are few moments more tender than those of a sunbathing cat.

Page 39: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Tiger sunbathing in a boxI am unable to envision anything quite as adorable as my cat Tiger lounging in the sun, cuddled in his precious little box.

He has been a fan of this box since he was just a kitten, and we have preserved it ever since. When Tiger was just nine months old, we almost threw out this little half box. He mauled a couch that day. The next day, we brought in the box from the recycling, and he has been a happy cat ever since.

I have taken many photos over the years of Tiger cuddled in this box, but I love how the light looks in this particular picture.

You can feel the warmth of the sun, Tiger purring, and envision him slowly closing his eyes and yawning. There are few moments more tender than those of a sunbathing cat.

Tiger cuddles in his box, basking in the sun.

HERO IMAGE

SIDE IMAGE

Page 40: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

<article  class="post">      <figure  class="post__hero-­‐image"><img  src="images/suncat.jpg"  alt="Golden  sunbeams  warm  a  cut  curled  up  in  a  box."  /></figure>      <div  class="post__inner">          <main  class="post__body"  role="main">              <h1  class="post__title">Tiger  sunbathing  in  a  box</h1>              <p>I  am  unable  to  envision  …  sunbathing  cat.</p>          </main>          <aside  class="post__aside"  role="complementary">              <figure  class="post__aside-­‐image">                  <img  src="images/suncat.jpg"  alt="Golden  sunbeams  warm  a  cut  curled  up  in  a  box."  />                  <figcaption  class="post__aside-­‐image-­‐caption">Tiger  cuddles  in  his  box,  basking  in  the  sun.</figcaption>              </figure>          </aside>      </div>  </article>

Page 41: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO IMAGE.post > .post__hero-image > img

Page 42: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

.post  {      @media  (min-­‐width:  100em)  {          left:  50%;          position:  relative;          transform:  translate(-­‐50%,  0);          width:  100rem;      }  }

.POST RULES

IMAGE RULESimg  {      height:  auto;      width:  100%;  }

Page 43: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO IMAGEBreakpoints .post .post__hero-image Final width

Default 100% 100% 100%

(min-width: 100em) 100rem 100% 100rem

Page 44: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE IMAGE.post > .post__inner > .post__aside > .post__aside-image > img

Page 45: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

.post__aside  {      padding:  5%;      width:  100%;  

   @media  (min-­‐width:  37.5em)  {          float:  left;          padding:  2%;          width:  40%;      }  

   @media  (min-­‐width:  75em)  {          padding:  1.5rem;    }  }

.POST__ASIDE RULES

Page 46: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE IMAGEBreakpoints .post .post__aside Final width

Default 100% 100% - 5% x 2 90%(min-width: 37.5em) 100% 40% - 2% x 2 36%

(min-width: 75em) 100% 40% - 1.5rem x 2 40% - 48px

(min-width: 100em) 100rem 40% - 1.5rem x 2 640px - 48px

Page 47: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

BALLPARK FIGURESDETERMINE INITIAL SOURCE FILE WIDTHS

Photo credit: Fuzzy Gerdes, “Parker Loooves the Cubs”, Flickr Creative Commons

Page 48: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO IMAGEBreakpoints Width Min px Max px

Default 100% 320 1599

(min-width: 100em) 100rem 1600 1600

Min size: 320pxMax size: 1600px

Page 49: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

RULE OF 25%WIDTH X 1.25 HEIGHT X 1.25 PIXELS X 1.5625

56.25% MORE PIXELS

Page 50: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO: RULE OF 25%320400500625781.25976.56251,220.7031251,525.87890631,907.3486329

Page 51: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE IMAGEBreakpoints Width Min px Max px

Default 90% 288 540(min-width: 37.5em) 36% 216 432(min-width: 75em) 40% - 48px 432 592

(min-width: 100em) 640px - 48px 592 592

Min size: 288pxMax size: 592px

Page 52: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE: RULE OF 25%288360450562.5703.125

Page 53: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE: -25% FROM TOP303.104378.88473.6592

Page 54: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

TWICE AS NICESCREEN RESOLUTION DENSITIES

Photo credit: Mrs eNil, “Bed cuddles”, Flickr Creative Commons

Page 55: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO: 2X SCREEN DENSITIES320400500625781.25976.56251,220.7031251,525.87890631,907.3486329

640800100012501562.51953.1252441.406253,051.75781253814.6972656

Page 56: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE: 2X SCREEN DENSITIES303.104378.88473.6592

606.208757.76947.21184

Page 57: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

TIDY UPSENSIBLE SOURCE FILE WIDTHS

Photo credit: Sandra Forbes, “Clean Kitty”, Flickr Creative Commons

Page 58: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO: TIDY NUMBERS320400500625781.25976.56251,220.7031251,525.87890631,907.3486329

320400500625800100012501600

Page 59: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO: TIDY NUMBERS320400500625800100012501600

25%

25%

25%

28%

25%

25%

28%

Page 60: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO: TIDY 2X320400500625800100012501600

640800100012501600200025003200

Page 61: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO: MORE TIDY 2X320400500640800100012801600

640800100012801600200025603200

Page 62: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO: MORE TIDY 2X320400500640800100012801600

640800100012801600200025603200

Page 63: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO: FINAL SOURCE WIDTHS320400500640800100012801600200025603200

25%

25%

25%28%

25%

25%

28%

25%

25.6%25%

Page 64: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO: FINAL SOURCE WIDTHS320400500640800100012801600200025603200

11 source widths

vs.

18 source widths

Page 65: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE: TIDY NUMBERS303.104378.88473.6592

300375470600

Page 66: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE: TIDY NUMBERS300375470600

25%

27%

27.7%

Page 67: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE: TIDY 2X300375470600

6007509401200

Page 68: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE: MORE TIDY 2X300375470600

6007509401200

Page 69: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE: FINAL SOURCE WIDTHS3003754706007509401200

25%

27%

25%

27.7%

25.33%

27.7%

Page 70: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE: FINAL SOURCE WIDTHS3003754706007509401200

7 source widths

vs.

8 source widths

Page 71: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIZES ATTRIBUTEQUICK ACCESS LAYOUT INFO

Photo credit: London Looks, “Kittens!”, Flickr Creative Commons

Page 72: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO: SIZES

<img  sizes="(min-­‐width:  100em)  100rem,  100vw">  

Breakpoints Final width Sizes width

Default 100% 100vw

(min-width: 100em) 100rem 100rem

Page 73: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE: SIZES

<img  sizes="(min-­‐width:  100em)    37rem,                          (min-­‐width:  75em)      calc(40vw  -­‐  3rem),                          (min-­‐width:  37.5em)  36vw,                                                                  90vw">  

Breakpoints Final width Sizes widthDefault 90% 90vw

(min-width: 37.5em) 36% 36vw(min-width: 75em) 40% - 48px calc(40vw - 3rem)(min-width: 100em) 640px - 48px 37rem

Page 74: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SRCSET ATTRIBUTELIST IMAGE SOURCE FILES WITH WIDTHS

Photo credit: Mathias Erhart, “kittens”, Flickr Creative Commons

Page 75: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO: SRCSET

320400500640800100012801600200025603200

<img  srcset="      hero320.jpg    320w,        hero400.jpg    400w,        hero500.jpg    500w,      hero640.jpg    640w,      hero800.jpg    800w,      hero1000.jpg  1000w,      hero1280.jpg  1280w,      hero1600.jpg  1600w,      hero2000.jpg  2000w,      hero2560.jpg  2560w,      hero3200.jpg  3200w">  

Page 76: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE: SRCSET

3003754706007509401200

<img  srcset="      side300.jpg    300w,        side375.jpg    375w,        side470.jpg    470w,      side600.jpg    600w,      side750.jpg    750w,      side940.jpg    940w,      side1200.jpg  1200w">  

Page 77: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

THIS SOUNDS LIKE A JOB FOR…

ROBOTS!

Photo credit: theresa21, “Daxie’s no match for the punching robots”, Flickr Creative Commons

Page 78: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

CSS RULESMAKE IMAGES FLUID

Photo credit: Kevin Pelrine, “Leroy the Ruler”, Flickr Creative Commons

Page 79: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

IMAGE RULES

img  {      height:  auto;      width:  100%;  }

Page 80: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

WIDTH: 100%

Page 81: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

MAX-WIDTH: 100% (MAYBE)

Page 82: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HOLD UP. TIME TO DRUPAL.

Page 83: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

BREAK DANCINGBREAKPOINTS AND BREAKPOINT GROUPS

Photo credit: Trish Hamme, “Ta-Da !!!!”, Flickr Creative Commons

Page 84: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Empty srcset is all we need

Page 85: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Add breakpoint group: Sizes

Select Empty srcset []

Page 86: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Export to theme .info file? Optional.

Page 87: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

THEME.empty:      label:  Empty      mediaQuery:  ''      weight:  1

DRUPAL 8 BREAKPOINTS.YML

Page 88: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SEND IN THE ROBOTSIMAGE STYLES

Photo credit: Andy Miicone, “Miisa”, Flickr Creative Commons

Page 89: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

HERO: FILE WIDTHS320400500640800100012801600200025603200

Page 90: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE: FILE WIDTHS3003754706007509401200

Page 91: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Image styles: Add style

Page 92: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Name style: width_X

rectangle_WxH square_WxH

Page 93: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint
Page 94: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Add width Allow upscaling

Page 95: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

LET’S MAP THIS OUTPICTURE MAPPINGS AND FALLBACK STYLES

Photo credit: Little Dog Laughed, “Geography Cat”, Flickr Creative Commons

Page 96: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Add mapping

Page 97: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Select breakpoint group

Page 98: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Mapping name Select sizes

Page 99: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Add responsive image style

Drupal 8!

Page 100: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

D8: Set fallback image style

Page 101: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

SIDE: SIZES<img  sizes="(min-­‐width:  100em)    37em,                          (min-­‐width:  75em)      calc(40vw  -­‐  3em),                          (min-­‐width:  37.5em)  36vw,                                                                  90vw">  

Page 102: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Enter sizes Select styles

Page 103: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

CHECK IT BEFORE YOU WRECK ITIMAGE QUALITY MATTERS

Photo credit: Woodleyworks, “Lucky was inexorably drawn to the mirror”, Flickr Creative Commons

Page 104: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Image quality

Page 105: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Try lower: 60?

Page 106: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

STYLE SELECTIONS VIA UIFIELD FORMATTERS AND YOU

Photo credit: George Pavlov, “I’m pretty kitty, right?”, Flickr Creative Commons

Page 107: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Field display

Page 108: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Change format to Picture

Page 109: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Select mapping, fallback

Page 110: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

STYLE SELECTIONS VIA CODETHEME PREPROCESSING FUNCTIONS AND MORE

Photo credit: Brian Dailey, “Cat + Code + Snow”, Flickr Creative Commons

Page 111: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

function  THEME_preprocess_node(&$variables)  {                  if  ($variables['type']  ==  'blog')  {          $fallback_style  =  'width_400';              if  ($account  =  user_load($node-­‐>uid))  {                  if  (isset($account-­‐>picture-­‐>uri)                      &&  ($mapping  =  picture_mapping_load('author_image'))                      &&  ($breakpoints  =  picture_get_mapping_breakpoints($mapping,  $fallback_style)))  {                          $image_options  =  array(                              'uri'  =>  $account-­‐>picture-­‐>uri,                              'alt'  =>  '',                              'breakpoints'  =>  $breakpoints,                              'style_name'  =>  $fallback_style,                          );                          $variables['user_picture']  =                            theme('picture',  $image_options);                  }              }        }  }

Page 112: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

   $content['side_image_responsive']  =  array(          '#type'  =>  'responsive_image',          '#uri'  =>  'public://side-­‐image.png',          '#attributes'  =>  array(              'alt'  =>  t('Hero  image'),              'title'  =>  t('Hero  image  title'),          ),          '#responsive_image_style_id'  =>  'hero',      );

Simpler in D8!

Page 113: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

MAKE THE WEB BETTERBeautiful photos + Fast loading photos

Page 114: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Pete Markham, “Domino the Cat, Week 2”, Flickr Creative Commons

Page 115: SIZING UP RESPONSIVE IMAGES - DrupalCon · 2016. 1. 28. · use responsive images in older browsers. drupal 7 picture and breakpoints modules. drupal 8 responsive image and breakpoint

Photo credit: Dave Emerson, “Trouble”, Flickr Creative Commons

Marc Drummond

@MarcDrummond

mdrummondIRC, drupal.org

marcdrummond.com

Front-end Developer, Lullabot