SlideShare a Scribd company logo
Practical 
Responsive 
Images 
http://unsplash.com/
A picture is worth a thousand words… 
…but the cost is much greater 
http://unsplash.com/
The cost of images 
http://en.wikipedia.org/wiki/Wikipedia:Size_comparisons 
198,000 Words 
http://httparchive.org/interesting.php?a=All&l=Jul%2015%202014 
1165kB 
Images 
Average Bytes per Page by 
Content Type (July 2014): 
If 1kB is 1024 ASCII characters 
6 chars/word 
An estimated average word length 
is five characters, plus a space, 
(1165kB * 1024) / 6 = ~198, 800 
(including HTML) 
(of a total: 1850kB) 
50-60 
img requests 
per page 
Average image 
size for JPEG 
was 30kB
The cost of images 
Pride and Prejudice 
apparently contains 
122,000 
words 
http://www.searchlit.org/novels/460.php
The cost of images
The Value of Images 
β€œPictures have the power to create an emotional response 
in the audience, which is worth its weight in gold. An image 
can also communicate instantly, as our brain can 
interpret them much quicker than text.” 
http://www.thoughtmechanics.com/the-importance-of-images-in-web-design/ 
! 
thoughtmechanics.com 
β€œIf I’d have to pick one single thing that 
would sell a product online, it’s images.” 
! 
Peep Laja (Conversion Coach)
The Value of Images 
Articles with images get 94% more total views 
Headshots of customer service reps on a web 
page can boost conversion rates by 20% 
In an ecommerce site, 67% of consumers say the 
quality of a product image is β€œvery important” in 
selecting and purchasing a product 
Including a Photo and a video in a press 
release increases views by over 45% 
60% of consumers are more likely to 
consider or contact a business when an 
image shows up in local search results 
http://www.jeremysaid.com/the-jaw-dropping-effect-that-images-can-have-on-your-conversion-rates/ 
http://www.jeffbullas.com/2012/05/28/6-powerful-reasons-why-you-should-include-images-in-your-marketing-infographic/
Images are powerful 
In some studies 
10-15x 
more viewers look at 
and engage with the 
content when the 
model is looking or 
gesturing towards it
Images are powerful 
In some studies 
10-15x 
more viewers look at 
and engage with the 
content when the 
model is looking or 
gesturing towards it 
http://thinkeyetracking.com/2009/06/cuing-customers-to-look-at-your-key-messages/ Photo courtesy of Christian Hambly
Guess the year? 
A lot has changed since 1993
Since first proposed in 1993, 
the <img > tag has remained 
mostly unchanged…. 
! 
…whereas the rest of the web-world 
change quite a bit!
Raster image options 
Background-images via CSS 
background-image: url('../images/header_800px.jpg'); 
@include mq($M){ 
background-image: url('../images/header_1400px.jpg'); 
} 
} 
*Stu Robson's media query mixin 
.banner{ 
Foreground images at 100% 
! 
.item_visuals img{ 
width: 100%; 
} 
……does nothing for payload.
…use alternatives 
to raster images 
if you can……. 
! 
SVG! 
! 
icon fonts 
http://icomoon.io/
Javascript Image Replacement 
using <noscript>, custom data- attributes and .insertAfter($(this)) 
<noscript data-imageid=β€˜bag.jpg’ data-small-imageid=β€˜bag_small.jpg’ data-large-imageid=β€˜bag_large.jpg’> 
<img src=β€˜bag_small.jpg’ alt='Bag' /> 
http://allbs.co.uk/2012/05/11/responsive-images-intro/ 
! 
</noscript> 
<script> 
! 
var areawidth = $(window).width(); 
var widthDownTosmall = 600; 
var widthUpToLarge = 1100; 
! 
$('noscript[data-imageid]').each(function(){ 
var imageBase=β€œimage/path"; 
var imageid = $(this).attr("data-imageid"); 
var imageSmall = $(this).attr("data-small-imageid"); 
var imageLarge = $(this).attr("data-large-imageid"); 
if (areawidth <= widthDownTosmall) {imageid = imageSmall; } 
if (areawidth >= widthUpToLarge) {imageid = imageLarge; } 
$('<img src="' + imageBase + imageid + '"/>').insertAfter($(this)); 
}); 
</script>
Enter our heroes: 
<picture> 
srcset/sizes attributes
Nitty gritty 
! 
<picture> 
<source media="(min-width: 40em)" srcset="apple-big.jpg 1x, apple-big-hd.jpg 2x"> 
<source srcset="apple-small.jpg 1x, apple-small-hd.jpg 2x"> 
<img src="apple-fallback.jpg" alt="How do you like them apples?"> 
</picture> 
<img src="apple-fallback.jpg" 
srcset="apple-big.jpg 1000w, apple-med.jpg 640w, apple-small.jpg 320w" 
sizes="(min-width: 40em) 50vw, 100vw" 
alt="How do you like them apples?" />
(As of : June 11th β€˜14) 
Progress 
(As of : August 17th β€˜14) 
http://responsiveimages.org/
How to enable 
chrome://flags/#enable-experimental- 
web-platform-features 
Firefox Nightly 
Tools > Web Developer > 
Developer Toolbar 
Chrome Canary
*BREAKING NEWS* 
Chrome 38 released 7th Oct 
! 
First stable browser with 
<picture> enabled by default!
Can I Use 
(As of : Aug 16th 2014) 
http://caniuse.com/#search=picture http://caniuse.com/#search=srcset
Can I Use
picturefill 
A responsive image polyfill. 
For today, and future-legacy-browsers 
http://scottjehl.github.io/picturefill/ 
<script> 
document.createElement( "picture" ); 
</script> 
<script src="picturefill.js" async></script> 
Developed and maintained by Filament Group
picture phil 
* Sorry
grab a copy of picturefill.js 
Use the <picture> element 
! 
*IE9 needs a bit of a workaround to avoid a conflict: 
<picture> 
<!--[if IE 9]><video style="display: none;”><![endif]--> 
<source srcset="/image1_big.jpg" media="(min-width: 1000px)"> 
<source srcset="/image1_medium.jpg" media="(min-width: 800px)"> 
<source srcset="/image_small.jpg"> 
<!--[if IE 9]></video><![endif]--> 
<img srcset="/image_fallback.jpg alt="context"> 
</picture> 
Try it today
Use Case 1: breakpoint optimised images (retina/pixel ratio) 
media="(min-width: 1000px)" 
media="(min-width: 400px)" 
srcset="/image1_big.jpg" 
srcset=β€œ/image1_small.jpg" 
http://responsiveimag.es/Practical_Example_1.html
Use Case 1: srcset, without sizes (assumes 100vw) 
<img 
srcset=β€œApple_800.jpg 800w, 
Apple_1200.jpg 1200w" 
src=β€œApple_fallback.jpg” 
alt=β€œHow do you like them Apples?"/> 
</div>
Use Case 2: Crop to point of interest (Art Direction) 
http://responsiveimag.es/Practical_Example_2.html
Use Case 2: Crop to point of interest (Art Direction)
Use Case 3: Device Orientation 
srcset="landscape_variant.jpg" media="(min-width: 
400px) and (orientation: landscape)" 
srcset="portrait_variant.jpg" media="(min-width: 
400px) and (orientation: portrait)" 
http://responsiveimag.es/Practical_Example_3.html
Use Case 4: Image type : webp/svg 
<picture> 
<type="image/webp" srcset="images/lilypad_600.webp" /> 
<img src="images/lilypad_600.jpg" alt="Lily pad" /> 
</picture>
Use Case 5: vw 
<img 
src=β€œApple_fallback.jpg” alt="How do you like them Apples?" 
sizes="(min-width: 640px) 50vw, 100vw" 
srcset=β€œApple_200.jpg 200w, 
Apple_400.jpg 400w, 
Apple_600.jpg 600w, 
Apple_800.jpg 800w, 
Apple_1200.jpg 1200w" /> 
</div> 
Viewport width 
If width β‰₯ 640px then use 50vw 
! 
i.e. Calculations use 50% of width 
50% 
Within the fluid context of responsive websites, 
the restrictive nature of the <img> element, and 
lack of CSS controls for foreground images, has 
not been the elephant in the room. It's just been 
the elephant that we couldn't agree what to do 
with….
Where do we get all those image variants? 
(scaling / CDN) 
Batch Statics 
v 
Server-side 
image manipulation 
Build Your Own 
v 
SaaS
Dynamic Imaging Systems 
At-request-time image variants: 
Control width, quality, sharpening…. 
! 
image.jpg?w=400&qlt=70&unsharp=0,1,1,7
Combining the two 
<picture> 
<!--[if IE 9]><video style="display: none;"><![endif]--> 
<source srcset="http://images.amplience.com/i/benco/Apple_Row2.jpg? 
w=1400&qlt=80&unsharp=0,1,1,7" media="(min-width: 1200px)"> 
<source srcset=β€œhttp://images.amplience.com/i/benco/Apple_Row2.jpg? 
w=1200&qlt=80&unsharp=0,1,1,7" media="(min-width: 1050px)"> 
<source srcset=β€œhttp://images.amplience.com/i/benco/Apple_Row2.jpg? 
pcrop=700,0,2500,800&w=950&qlt=80&unsharp=0,1,1,7" media="(min-width: 850px)"> 
<source srcset=β€œhttp://images.amplience.com/i/benco/Apple_Row2.jpg? 
pcrop=1300,0,1900,800&w=850&qlt=80&unsharp=0,1,1,7" media="(min-width: 600px)"> 
<source srcset=β€œhttp://images.amplience.com/i/benco/Red_And_Green_Apples2.jpg? 
w=600&qlt=80&unsharp=0,1,1,7"> 
<!--[if IE 9]></video><![endif]--> 
<img srcset="http://images.amplience.com/i/benco/Apple2.jpg?w=600&qlt=80" 
alt="How do you like them Apples?"> 
</picture>
Combining the two 
<img 
src="http://images.amplience.com/i/benco/Apple2.jpg?w=400&qlt=80" 
Viewport width 
50% 
Within the fluid context of responsive websites, 
the restrictive nature of the <img> element, and 
lack of CSS controls for foreground images, has 
not been the elephant in the room. It's just been 
the elephant that we couldn't agree what to do 
with…. 
alt="How do you like them Apples?" 
sizes="(min-width: 640px) 50vw, 100vw" 
srcset="http://images.amplience.com/i/benco/Apple_Row2.jpg?w=200&qlt=80&unsharp=0,1,1,7 200w, 
http://images.amplience.com/i/benco/Apple_Row2.jpg?w=400&qlt=80&unsharp=0,1,1,7 400w, 
http://images.amplience.com/i/benco/Apple_Row2.jpg?w=600&qlt=80&unsharp=0,1,1,7 600w, 
http://images.amplience.com/i/benco/Apple_Row2.jpg?w=800&qlt=80&unsharp=0,1,1,7 800w, 
http://images.amplience.com/i/benco/Apple_Row2.jpg?w=1200&qlt=80&unsharp=0,1,1,7 1200w" /> 
! 
</div>
One last thing….
AngularJS 
<body> 
<img src=β€œApple.jpg" picture-assetid="Apple_Row2" 
alt="How do you like them apples?"/> 
</body> 
angular.module('components', []) 
.directive('pictureAssetid', function(){ 
return { 
restrict: 'A', 
replace:true, 
transclude: true, 
scope : { 
caption: '@', 
pictureAssetid: '@' 
}, 
templateUrl: 'partials/image-picture.html' 
} 
}) 
! 
angular.module('HelloApp', ['components']) 
<picture> 
<!--[if IE 9]><video style="display: none;"><![endif]--> 
<source srcset="http://images.amplience.com/i/benco/{{pictureAssetid}}.jpg?w=1400&qlt=80&unsharp=0,1,1,7" media="(min-width: 1000px)"> 
<source srcset="http://images.amplience.com/i/benco/{{pictureAssetid}}.jpg?w=800&qlt=80&unsharp=0,1,1,7" media="(min-width: 800px)"> 
<source srcset="http://images.amplience.com/i/benco/{{pictureAssetid}}.jpg?w=600&qlt=80&unsharp=0,1,1,7"> 
<!--[if IE 9]></video><![endif]--> 
<img srcset="http://images.amplience.com/i/benco/{{pictureAssetid}}.jpg?w=400&qlt=80" > 
</picture>
<picture> 
/ 
srcset 
Dynamic 
Imaging 
System 
Practical 
Responsive 
Images 
+ =
responsiveimag.es 
@bseymour 
Thank you

More Related Content

PDF
Practical Responsive Images : from Breaking Borders
PDF
Imagecon 2019 - Aaron Gustafson
PDF
Practical Responsive Images : Digital Henley : May 2015
PDF
Илья ΠŸΡƒΡ…Π°Π»ΡŒΡΠΊΠΈΠΉ (EPAM Systems)
Β 
PDF
Responsive Web in Brief
Β 
PDF
Bilder usw...
POTX
Its time to stop stalling novi sad
DOCX
Speed and Performance Optimization Technique of a website
Practical Responsive Images : from Breaking Borders
Imagecon 2019 - Aaron Gustafson
Practical Responsive Images : Digital Henley : May 2015
Илья ΠŸΡƒΡ…Π°Π»ΡŒΡΠΊΠΈΠΉ (EPAM Systems)
Β 
Responsive Web in Brief
Β 
Bilder usw...
Its time to stop stalling novi sad
Speed and Performance Optimization Technique of a website

What's hot (11)

PDF
Responsive Design: Mehr als CSS
KEY
Garfield hs ap cs 2009 - intarwebs
PDF
Bilder einbinden ist kein Thema, oder?
RTF
Slides pour blog
Β 
PDF
High Performance Images
PDF
AtlasCamp 2013: Modernizing your Plugin UI
PDF
Yes, browsers can do that! Hybrid and future web meetup at Jayway
PDF
RESS – Responsive Webdesign and Server Side Components
PPTX
Java - Persist and Replay Runtime Data
PDF
The specs behind the sex, mobile-friendly layout beyond the desktop
PDF
AtlasCamp 2010: Understanding the Atlassian Platform - Tim Pettersen
Responsive Design: Mehr als CSS
Garfield hs ap cs 2009 - intarwebs
Bilder einbinden ist kein Thema, oder?
Slides pour blog
Β 
High Performance Images
AtlasCamp 2013: Modernizing your Plugin UI
Yes, browsers can do that! Hybrid and future web meetup at Jayway
RESS – Responsive Webdesign and Server Side Components
Java - Persist and Replay Runtime Data
The specs behind the sex, mobile-friendly layout beyond the desktop
AtlasCamp 2010: Understanding the Atlassian Platform - Tim Pettersen
Ad

Viewers also liked (9)

PPTX
Bracco, gonzΓ‘lez, velΓ‘zquez
PPTX
Camacho-Froschauer-Brest-Pierotti
PPTX
Transforming Business with the Customer in Mind
PDF
Technical Approaches to Improving the Scratch Resistance of TPO. Part I: Su...
PPTX
Drone.Mechanism
PPTX
Mushroom cultivation A Presentation By Mr Allah Dad Khan Former Director Gene...
PDF
Ecuaciones Lineales.
PDF
How ntfs works br
DOCX
Quality of Service
Bracco, gonzΓ‘lez, velΓ‘zquez
Camacho-Froschauer-Brest-Pierotti
Transforming Business with the Customer in Mind
Technical Approaches to Improving the Scratch Resistance of TPO. Part I: Su...
Drone.Mechanism
Mushroom cultivation A Presentation By Mr Allah Dad Khan Former Director Gene...
Ecuaciones Lineales.
How ntfs works br
Quality of Service
Ad

Similar to Practical Responsive Images - from Second Wednesday (20)

PDF
Responsive Images in the Real World - presented at JavaScript Open 2015
PDF
Ben Seymour "Practical Responsive Images"
PPTX
Responsive images
PDF
Responsive images are here. Now what?
PDF
The things browsers can do! SAE Alumni Convention 2014
PDF
Responsive Websites
PDF
Delivering Responsive Images
PDF
High Performance Images: Beautiful Shouldn't Mean Slow
PDF
Practical Responsive Images : MK Geek Night
PDF
2022.04 - CSS Day IT - Images Optimisation 4.0
PDF
Responsive Web Design: Clever Tips and Techniques
PDF
Responsive images, an html 5.1 standard
PDF
Pinkoi Mobile Web
PDF
Responsive Responsive Design
PDF
[rwdsummit] Adaptive Images in Responsive Web Design
PDF
[cssdevconf] Adaptive Images in RWD
PDF
[rwdsummit2012] Adaptive Images in Responsive Web Design
ODP
The status of living HTML (highlights)
PDF
[html5tx] Adaptive Images in Responsive Web Design
KEY
HTML5: Markup Evolved
Responsive Images in the Real World - presented at JavaScript Open 2015
Ben Seymour "Practical Responsive Images"
Responsive images
Responsive images are here. Now what?
The things browsers can do! SAE Alumni Convention 2014
Responsive Websites
Delivering Responsive Images
High Performance Images: Beautiful Shouldn't Mean Slow
Practical Responsive Images : MK Geek Night
2022.04 - CSS Day IT - Images Optimisation 4.0
Responsive Web Design: Clever Tips and Techniques
Responsive images, an html 5.1 standard
Pinkoi Mobile Web
Responsive Responsive Design
[rwdsummit] Adaptive Images in Responsive Web Design
[cssdevconf] Adaptive Images in RWD
[rwdsummit2012] Adaptive Images in Responsive Web Design
The status of living HTML (highlights)
[html5tx] Adaptive Images in Responsive Web Design
HTML5: Markup Evolved

More from Ben Seymour (8)

PDF
How Was Your Weekend?
PDF
Making The Most Of Your Fears
PDF
Has responsive had it's day? : Amplience Customer Day 2014
PDF
Are you sitting comfortably : MKGN
PDF
Are you sitting comfortably?
PDF
7 Customer Experience Tips for eCommerce : Qubit Bright Sparks : 29th April 2014
PPTX
Dynamic Media and Responsive Web Design
PPTX
Adobe Summit EMEA 2012 : 16706 Optimise Mobile Experience
How Was Your Weekend?
Making The Most Of Your Fears
Has responsive had it's day? : Amplience Customer Day 2014
Are you sitting comfortably : MKGN
Are you sitting comfortably?
7 Customer Experience Tips for eCommerce : Qubit Bright Sparks : 29th April 2014
Dynamic Media and Responsive Web Design
Adobe Summit EMEA 2012 : 16706 Optimise Mobile Experience

Recently uploaded (20)

PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PPTX
newyork.pptxirantrafgshenepalchinachinane
PDF
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
PPTX
presentation_pfe-universite-molay-seltan.pptx
PPTX
innovation process that make everything different.pptx
PPTX
SAP Ariba Sourcing PPT for learning material
PPT
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
PDF
Introduction to the IoT system, how the IoT system works
PPTX
E -tech empowerment technologies PowerPoint
PPTX
artificialintelligenceai1-copy-210604123353.pptx
Β 
PPTX
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PDF
Sims 4 Historia para lo sims 4 para jugar
PPT
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PPTX
Introduction to Information and Communication Technology
PPTX
Introduction to cybersecurity and digital nettiquette
PDF
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
PDF
An introduction to the IFRS (ISSB) Stndards.pdf
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
Unit-1 introduction to cyber security discuss about how to secure a system
newyork.pptxirantrafgshenepalchinachinane
πŸ’° π”πŠπ“πˆ πŠπ„πŒπ„ππ€ππ†π€π πŠπˆππ„π‘πŸ’πƒ π‡π€π‘πˆ 𝐈𝐍𝐈 πŸπŸŽπŸπŸ“ πŸ’°
Β 
presentation_pfe-universite-molay-seltan.pptx
innovation process that make everything different.pptx
SAP Ariba Sourcing PPT for learning material
isotopes_sddsadsaadasdasdasdasdsa1213.ppt
Introduction to the IoT system, how the IoT system works
E -tech empowerment technologies PowerPoint
artificialintelligenceai1-copy-210604123353.pptx
Β 
June-4-Sermon-Powerpoint.pptx USE THIS FOR YOUR MOTIVATION
SASE Traffic Flow - ZTNA Connector-1.pdf
Sims 4 Historia para lo sims 4 para jugar
FIRE PREVENTION AND CONTROL PLAN- LUS.FM.MQ.OM.UTM.PLN.00014.ppt
Slides PPTX World Game (s) Eco Economic Epochs.pptx
Introduction to Information and Communication Technology
Introduction to cybersecurity and digital nettiquette
FINAL CALL-6th International Conference on Networks & IOT (NeTIOT 2025)
An introduction to the IFRS (ISSB) Stndards.pdf
Module 1 - Cyber Law and Ethics 101.pptx

Practical Responsive Images - from Second Wednesday

  • 1. Practical Responsive Images http://unsplash.com/
  • 2. A picture is worth a thousand words… …but the cost is much greater http://unsplash.com/
  • 3. The cost of images http://en.wikipedia.org/wiki/Wikipedia:Size_comparisons 198,000 Words http://httparchive.org/interesting.php?a=All&l=Jul%2015%202014 1165kB Images Average Bytes per Page by Content Type (July 2014): If 1kB is 1024 ASCII characters 6 chars/word An estimated average word length is five characters, plus a space, (1165kB * 1024) / 6 = ~198, 800 (including HTML) (of a total: 1850kB) 50-60 img requests per page Average image size for JPEG was 30kB
  • 4. The cost of images Pride and Prejudice apparently contains 122,000 words http://www.searchlit.org/novels/460.php
  • 5. The cost of images
  • 6. The Value of Images β€œPictures have the power to create an emotional response in the audience, which is worth its weight in gold. An image can also communicate instantly, as our brain can interpret them much quicker than text.” http://www.thoughtmechanics.com/the-importance-of-images-in-web-design/ ! thoughtmechanics.com β€œIf I’d have to pick one single thing that would sell a product online, it’s images.” ! Peep Laja (Conversion Coach)
  • 7. The Value of Images Articles with images get 94% more total views Headshots of customer service reps on a web page can boost conversion rates by 20% In an ecommerce site, 67% of consumers say the quality of a product image is β€œvery important” in selecting and purchasing a product Including a Photo and a video in a press release increases views by over 45% 60% of consumers are more likely to consider or contact a business when an image shows up in local search results http://www.jeremysaid.com/the-jaw-dropping-effect-that-images-can-have-on-your-conversion-rates/ http://www.jeffbullas.com/2012/05/28/6-powerful-reasons-why-you-should-include-images-in-your-marketing-infographic/
  • 8. Images are powerful In some studies 10-15x more viewers look at and engage with the content when the model is looking or gesturing towards it
  • 9. Images are powerful In some studies 10-15x more viewers look at and engage with the content when the model is looking or gesturing towards it http://thinkeyetracking.com/2009/06/cuing-customers-to-look-at-your-key-messages/ Photo courtesy of Christian Hambly
  • 10. Guess the year? A lot has changed since 1993
  • 11. Since first proposed in 1993, the <img > tag has remained mostly unchanged…. ! …whereas the rest of the web-world change quite a bit!
  • 12. Raster image options Background-images via CSS background-image: url('../images/header_800px.jpg'); @include mq($M){ background-image: url('../images/header_1400px.jpg'); } } *Stu Robson's media query mixin .banner{ Foreground images at 100% ! .item_visuals img{ width: 100%; } ……does nothing for payload.
  • 13. …use alternatives to raster images if you can……. ! SVG! ! icon fonts http://icomoon.io/
  • 14. Javascript Image Replacement using <noscript>, custom data- attributes and .insertAfter($(this)) <noscript data-imageid=β€˜bag.jpg’ data-small-imageid=β€˜bag_small.jpg’ data-large-imageid=β€˜bag_large.jpg’> <img src=β€˜bag_small.jpg’ alt='Bag' /> http://allbs.co.uk/2012/05/11/responsive-images-intro/ ! </noscript> <script> ! var areawidth = $(window).width(); var widthDownTosmall = 600; var widthUpToLarge = 1100; ! $('noscript[data-imageid]').each(function(){ var imageBase=β€œimage/path"; var imageid = $(this).attr("data-imageid"); var imageSmall = $(this).attr("data-small-imageid"); var imageLarge = $(this).attr("data-large-imageid"); if (areawidth <= widthDownTosmall) {imageid = imageSmall; } if (areawidth >= widthUpToLarge) {imageid = imageLarge; } $('<img src="' + imageBase + imageid + '"/>').insertAfter($(this)); }); </script>
  • 15. Enter our heroes: <picture> srcset/sizes attributes
  • 16. Nitty gritty ! <picture> <source media="(min-width: 40em)" srcset="apple-big.jpg 1x, apple-big-hd.jpg 2x"> <source srcset="apple-small.jpg 1x, apple-small-hd.jpg 2x"> <img src="apple-fallback.jpg" alt="How do you like them apples?"> </picture> <img src="apple-fallback.jpg" srcset="apple-big.jpg 1000w, apple-med.jpg 640w, apple-small.jpg 320w" sizes="(min-width: 40em) 50vw, 100vw" alt="How do you like them apples?" />
  • 17. (As of : June 11th β€˜14) Progress (As of : August 17th β€˜14) http://responsiveimages.org/
  • 18. How to enable chrome://flags/#enable-experimental- web-platform-features Firefox Nightly Tools > Web Developer > Developer Toolbar Chrome Canary
  • 19. *BREAKING NEWS* Chrome 38 released 7th Oct ! First stable browser with <picture> enabled by default!
  • 20. Can I Use (As of : Aug 16th 2014) http://caniuse.com/#search=picture http://caniuse.com/#search=srcset
  • 22. picturefill A responsive image polyfill. For today, and future-legacy-browsers http://scottjehl.github.io/picturefill/ <script> document.createElement( "picture" ); </script> <script src="picturefill.js" async></script> Developed and maintained by Filament Group
  • 23. picture phil * Sorry
  • 24. grab a copy of picturefill.js Use the <picture> element ! *IE9 needs a bit of a workaround to avoid a conflict: <picture> <!--[if IE 9]><video style="display: none;”><![endif]--> <source srcset="/image1_big.jpg" media="(min-width: 1000px)"> <source srcset="/image1_medium.jpg" media="(min-width: 800px)"> <source srcset="/image_small.jpg"> <!--[if IE 9]></video><![endif]--> <img srcset="/image_fallback.jpg alt="context"> </picture> Try it today
  • 25. Use Case 1: breakpoint optimised images (retina/pixel ratio) media="(min-width: 1000px)" media="(min-width: 400px)" srcset="/image1_big.jpg" srcset=β€œ/image1_small.jpg" http://responsiveimag.es/Practical_Example_1.html
  • 26. Use Case 1: srcset, without sizes (assumes 100vw) <img srcset=β€œApple_800.jpg 800w, Apple_1200.jpg 1200w" src=β€œApple_fallback.jpg” alt=β€œHow do you like them Apples?"/> </div>
  • 27. Use Case 2: Crop to point of interest (Art Direction) http://responsiveimag.es/Practical_Example_2.html
  • 28. Use Case 2: Crop to point of interest (Art Direction)
  • 29. Use Case 3: Device Orientation srcset="landscape_variant.jpg" media="(min-width: 400px) and (orientation: landscape)" srcset="portrait_variant.jpg" media="(min-width: 400px) and (orientation: portrait)" http://responsiveimag.es/Practical_Example_3.html
  • 30. Use Case 4: Image type : webp/svg <picture> <type="image/webp" srcset="images/lilypad_600.webp" /> <img src="images/lilypad_600.jpg" alt="Lily pad" /> </picture>
  • 31. Use Case 5: vw <img src=β€œApple_fallback.jpg” alt="How do you like them Apples?" sizes="(min-width: 640px) 50vw, 100vw" srcset=β€œApple_200.jpg 200w, Apple_400.jpg 400w, Apple_600.jpg 600w, Apple_800.jpg 800w, Apple_1200.jpg 1200w" /> </div> Viewport width If width β‰₯ 640px then use 50vw ! i.e. Calculations use 50% of width 50% Within the fluid context of responsive websites, the restrictive nature of the <img> element, and lack of CSS controls for foreground images, has not been the elephant in the room. It's just been the elephant that we couldn't agree what to do with….
  • 32. Where do we get all those image variants? (scaling / CDN) Batch Statics v Server-side image manipulation Build Your Own v SaaS
  • 33. Dynamic Imaging Systems At-request-time image variants: Control width, quality, sharpening…. ! image.jpg?w=400&qlt=70&unsharp=0,1,1,7
  • 34. Combining the two <picture> <!--[if IE 9]><video style="display: none;"><![endif]--> <source srcset="http://images.amplience.com/i/benco/Apple_Row2.jpg? w=1400&qlt=80&unsharp=0,1,1,7" media="(min-width: 1200px)"> <source srcset=β€œhttp://images.amplience.com/i/benco/Apple_Row2.jpg? w=1200&qlt=80&unsharp=0,1,1,7" media="(min-width: 1050px)"> <source srcset=β€œhttp://images.amplience.com/i/benco/Apple_Row2.jpg? pcrop=700,0,2500,800&w=950&qlt=80&unsharp=0,1,1,7" media="(min-width: 850px)"> <source srcset=β€œhttp://images.amplience.com/i/benco/Apple_Row2.jpg? pcrop=1300,0,1900,800&w=850&qlt=80&unsharp=0,1,1,7" media="(min-width: 600px)"> <source srcset=β€œhttp://images.amplience.com/i/benco/Red_And_Green_Apples2.jpg? w=600&qlt=80&unsharp=0,1,1,7"> <!--[if IE 9]></video><![endif]--> <img srcset="http://images.amplience.com/i/benco/Apple2.jpg?w=600&qlt=80" alt="How do you like them Apples?"> </picture>
  • 35. Combining the two <img src="http://images.amplience.com/i/benco/Apple2.jpg?w=400&qlt=80" Viewport width 50% Within the fluid context of responsive websites, the restrictive nature of the <img> element, and lack of CSS controls for foreground images, has not been the elephant in the room. It's just been the elephant that we couldn't agree what to do with…. alt="How do you like them Apples?" sizes="(min-width: 640px) 50vw, 100vw" srcset="http://images.amplience.com/i/benco/Apple_Row2.jpg?w=200&qlt=80&unsharp=0,1,1,7 200w, http://images.amplience.com/i/benco/Apple_Row2.jpg?w=400&qlt=80&unsharp=0,1,1,7 400w, http://images.amplience.com/i/benco/Apple_Row2.jpg?w=600&qlt=80&unsharp=0,1,1,7 600w, http://images.amplience.com/i/benco/Apple_Row2.jpg?w=800&qlt=80&unsharp=0,1,1,7 800w, http://images.amplience.com/i/benco/Apple_Row2.jpg?w=1200&qlt=80&unsharp=0,1,1,7 1200w" /> ! </div>
  • 37. AngularJS <body> <img src=β€œApple.jpg" picture-assetid="Apple_Row2" alt="How do you like them apples?"/> </body> angular.module('components', []) .directive('pictureAssetid', function(){ return { restrict: 'A', replace:true, transclude: true, scope : { caption: '@', pictureAssetid: '@' }, templateUrl: 'partials/image-picture.html' } }) ! angular.module('HelloApp', ['components']) <picture> <!--[if IE 9]><video style="display: none;"><![endif]--> <source srcset="http://images.amplience.com/i/benco/{{pictureAssetid}}.jpg?w=1400&qlt=80&unsharp=0,1,1,7" media="(min-width: 1000px)"> <source srcset="http://images.amplience.com/i/benco/{{pictureAssetid}}.jpg?w=800&qlt=80&unsharp=0,1,1,7" media="(min-width: 800px)"> <source srcset="http://images.amplience.com/i/benco/{{pictureAssetid}}.jpg?w=600&qlt=80&unsharp=0,1,1,7"> <!--[if IE 9]></video><![endif]--> <img srcset="http://images.amplience.com/i/benco/{{pictureAssetid}}.jpg?w=400&qlt=80" > </picture>
  • 38. <picture> / srcset Dynamic Imaging System Practical Responsive Images + =