SlideShare uma empresa Scribd logo
1 de 55
Vector Graphics on the Web
                    Pascal Rettig
                    @cykod
Vector vs. Raster
Raster = Pixels = Bitmaps = .PNG, .JPEG ...
Vector = Primitives = Shapes = .AI, .SVG

Vectors can easily be “Rasterized” at a
certain resolution into Bitmaps
Rasters cannot easily be “Vectorized”
without a whole lot of work
Why do we care?
Why do we care?
• Designers often create as vectors anyway.
Why do we care?
• Designers often create as vectors anyway.
• Resolution independent
Why do we care?
• Designers often create as vectors anyway.
• Resolution independent
• Smaller file size (when used appropriately)
Why do we care?
• Designers often create as vectors anyway.
• Resolution independent
• Smaller file size (when used appropriately)
Hmm, sounds like they would be good for
               mobile...
What are the options:
What are the options:
• Two W3C approved: SVG, Canvas
What are the options:
• Two W3C approved: SVG, Canvas
•   One “IE Special”: VML
What are the options:
• Two W3C approved: SVG, Canvas
•   One “IE Special”: VML

•   One “Sorta-kinda-vectorlike”: CSS3
Scalable Vector Graphics
SVG
• XML based format
• SVG 1.1 W3C Recommendation since 2003
• Not something you generally write by hand -
  Create with Illustrator or Inkscape
• Paths, Shapes, Fonts,Text, Fills, Gradients, Patterns,
The Dream
  (not reality)
The Dream
                  (not reality)

Use as an image:
<img src=‘images/tiger.svgz’/>
The Dream
                    (not reality)

Use as an image:
<img src=‘images/tiger.svgz’/>


or Embed Directly:
<html xmlns:svg="http://www.w3.org/2000/svg">
...
<svg:svg width="300" height="100" version="1.1" >
    <svg:circle cx="100" cy="50" r="40"
            stroke="black" stroke-width="2"
fill="red" />
</svg:svg>
The reality
The reality




              http://en.wikipedia.org/wiki/
Comparison_of_layout_engines_(Scalable_Vector_Graphics)
The Reality (TL;DR)
The Reality (TL;DR)
• Only Chrome, FF4 support gzipped SVG
• Only Chrome, FF4 support HTML5 Direct
  Embedding
• IE Support only coming in IE9
The Solution?
Use a library!
SVG Web
Use’s Native SVG or Flash
You still write SVG files / data
http://code.google.com/p/svgweb/

Raphael.js
Uses Native SVG or VML
Javascript API
http://raphaeljs.com/
SVG Web
<script src="svg.js"></script>


Then embed with an object tag or:
<script type="image/svg+xml">
  <svg width="400" height="300" id="svg11242"> ... </svg>
</script>



Scriptable from JavaScript pretty much normally
Raphael.js

var paper = Raphael(10, 50, 320, 200);

var circle = paper.circle(50, 40, 10);

circle.attr("fill", "#f00");
circle.attr("stroke", "#fff");
Other Common uses

Protovis - the graphing library you always wanted
   Cufon - font replacement with SVG/VML
Attack Vector B:
   <canvas>
HTML5 Canvas Tag
• Standardized by the WHATWG (2007)
• Grew out of WebKit (Dashboard Widgets)
• Javascript interface to a bunch o’ Pixels
Pixels?
Where are the Vectors?
Pixels?
Where are the Vectors?
<canvas> only stores pixel data.
But, <canvas> has drawing primitives for:
Rectangles, Lines, Quadtratic & Beizer Curves, Arcs,
Fills, Text, Gradients...
All drawing is done via a Javascript API
Canvas Example
<canvas id=”canvas” width=”150″ height=”150″>
   Your Browser don’t be supporting canvas
</canvas>

var canvas = document.getElementById(“canvas”);
if (canvas.getContext) {
   var ctx = canvas.getContext(“2d”);
   ctx.fillStyle = “rgb(100,0,0)”;
   ctx.fillRect (0, 0, 100, 100);
}



        https://developer.mozilla.org/en/
        drawing_graphics_with_canvas
Example #2: JS1K


                     http://marijnhaverbeke.nl/js1k/
     c=document.body.children[0];h=t=150;L=w=c.width=800;u=D=50;H=[];R=Math.random;for($ in C=
c.getContext('2d'))C[$[J=X=Y=0]+($[6]||'')]=C[$];setInterval("if(D)for(x=405,i=y=I=0;i<1e4;)L=
H[i++]=i<9|L<w&R()<.3?w:R()*u+80|0;$=++t%99-u;$=$*$/8+20;y+=Y;x+=y-H[(x+X)/u|0]>9?0:X;j=H[o=
x/u|0];Y=y<j|Y<0?Y+1:(y=j,J?-10:0);with(C){A=function(c,x,y,r){r&&a(x,y,r,0,7,0);fillStyle=c.P
?c:'#'+'ceff99ff78f86eeaaffffd45333'.substr(c*3,3);f();ba()};for(D=Z=0;Z<21;Z++){Z<7&&A(Z%6,w/
2,235,Z?250-15*Z:w);i=o-5+Z;S=x-i*u;B=S>9&S<41;ta(u-S,0);G=cL(0,T=H[i],0,T+9);T%6||(A(2,25,T-7
,5),y^j||B&&(H[i]-=.1,I++));G.P=G.addColorStop;G.P(0,i%7?'#7e3':(i^o||y^T||(y=H[i]+=$/99),
'#c7a'));G.P(1,'#ca6');i%4&&A(6,t/2%200,9,i%2?27:33);m(-6,h);qt(-6,T,3,T);l(47,T);qt(56,T,56,
h);A(G);i%3?0:T<w?(A(G,33,T-15,10),fc(31,T-7,4,9)):(A(7,25,$,9),A(G,25,$,5),fc(24,$,2,h),D=B&y
>$-9?1:D);ta(S-u,0)}A(6,u,y-9,11);A(5,M=u+X*.7,Q=y-9+Y/5,8);A(8,M,Q,5);fx(I+'¢',5,15)}D=y>h?1:D"
,u);onkeydown=onkeyup=function(e){E=e.type[5]?4:0;e=e.keyCode;J=e^38?J:E;X=e^37?e^39?X:E:-E}
Canvas Reality...
Canvas Reality...
• No native IE support
Canvas Reality...
• No native IE support
• Current browser implementations are slow
Canvas Near future...
Canvas Near future...

• IE Support in IE9 (IE6-IE8 w/ excanvas.js)
Canvas Near future...

• IE Support in IE9 (IE6-IE8 w/ excanvas.js)
• Next-gen browser support hardware-
  accelerated-awesomeness across the board
Canvas Near future...

• IE Support in IE9 (IE6-IE8 w/ excanvas.js)
• Next-gen browser support hardware-
  accelerated-awesomeness across the board
• WebGL support
Canvas Status




Q1 2010   Q4 2010   Q2 2011   Q4 2011
The pseudo-option:
      CSS3
CSS3 features that replace
      bitmap hacks:
Rounded corners - *-border-radius
Drop shadows: *-box-shadow
Text Shadows: text-shadow
Gradients: *-gradient
Fonts: @font-face
CSS3 Caveats
 You probably want to use a CSS Framework
such as SASS/LESS to DRY the vendor prefixes.

    IE6-8 - fake it with http://css3pie.com/
What also can be done:




   http://graphicpeel.com/cssiosicons
How
• Gradients, Rounded Corners, Shadows +
• Borders
• Rotations
• Pseudo-elements
• Transforms
• Z-index Masking
• A bunch of nested <div>’s
A Good idea? Maybe.
      • CSS3 Icons probably not worth the markup
        complexity.
      • But a re-scalable pure CSS logo...



http://www.csstemplateheaven.com/articlestutorials/pure-
                      css3-logo/
So SVG or Canvas?
SVG vs. Canvas
SVG vs. Canvas
SVG
SVG vs. Canvas
SVG         Canvas
SVG vs. Canvas
         SVG             Canvas




Persistent Scene Graph
  Hover, Click Events
Browser does the work
SVG vs. Canvas
         SVG                    Canvas




Persistent Scene Graph    Just Pixels (can R/W)
  Hover, Click Events    Own Event calculations
Browser does the work       Full canvas refresh
Bonus
Yo Dawg, I heard you
like vector graphics...




    http://burst.bocoup.com/
Yo Dawg, I heard you
like vector graphics...
So I put SVG in your Canvas so you could
       animate while you rasterize.




       http://burst.bocoup.com/
Yo Dawg, I heard you
like vector graphics...
So I put SVG in your Canvas so you could
       animate while you rasterize.




       http://burst.bocoup.com/
Thanks!
pascal@cykod.com
     @cykod

Mais conteúdo relacionado

Mais procurados

Accessibility Hacks version 2
Accessibility Hacks version 2Accessibility Hacks version 2
Accessibility Hacks version 2Graham Armfield
 
Quality Development with CSS3
Quality Development with CSS3Quality Development with CSS3
Quality Development with CSS3Shay Howe
 
Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018Graham Armfield
 
CSS3: Are you experienced?
CSS3: Are you experienced?CSS3: Are you experienced?
CSS3: Are you experienced?Denise Jacobs
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Erin M. Kidwell
 
Sass - Getting Started with Sass!
Sass - Getting Started with Sass!Sass - Getting Started with Sass!
Sass - Getting Started with Sass!Eric Sembrat
 
CSS3: Simply Responsive
CSS3: Simply ResponsiveCSS3: Simply Responsive
CSS3: Simply ResponsiveDenise Jacobs
 
Rockstar Graphics with HTML5
Rockstar Graphics with HTML5Rockstar Graphics with HTML5
Rockstar Graphics with HTML5Dave Balmer
 
New Elements & Features in CSS3
New Elements & Features in CSS3New Elements & Features in CSS3
New Elements & Features in CSS3Jamshid Hashimi
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3Doris Chen
 
Making Your Own CSS Framework
Making Your Own CSS FrameworkMaking Your Own CSS Framework
Making Your Own CSS FrameworkDan Sagisser
 

Mais procurados (20)

Before Going Vector
Before Going VectorBefore Going Vector
Before Going Vector
 
Accessibility Hacks version 2
Accessibility Hacks version 2Accessibility Hacks version 2
Accessibility Hacks version 2
 
Quality Development with CSS3
Quality Development with CSS3Quality Development with CSS3
Quality Development with CSS3
 
Html5
Html5Html5
Html5
 
Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018Accessibility Hacks Wordcamp Manchester October 2018
Accessibility Hacks Wordcamp Manchester October 2018
 
Html5
Html5Html5
Html5
 
CSS3: Are you experienced?
CSS3: Are you experienced?CSS3: Are you experienced?
CSS3: Are you experienced?
 
Html5 more than just html5 v final
Html5  more than just html5 v finalHtml5  more than just html5 v final
Html5 more than just html5 v final
 
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
Girl Develop It Cincinnati: Intro to HTML/CSS Class 4
 
Sass - Getting Started with Sass!
Sass - Getting Started with Sass!Sass - Getting Started with Sass!
Sass - Getting Started with Sass!
 
CSS3: Simply Responsive
CSS3: Simply ResponsiveCSS3: Simply Responsive
CSS3: Simply Responsive
 
Rockstar Graphics with HTML5
Rockstar Graphics with HTML5Rockstar Graphics with HTML5
Rockstar Graphics with HTML5
 
Intro to CSS3
Intro to CSS3Intro to CSS3
Intro to CSS3
 
HTML5 - A Whirlwind tour
HTML5 - A Whirlwind tourHTML5 - A Whirlwind tour
HTML5 - A Whirlwind tour
 
Css3
Css3Css3
Css3
 
New Elements & Features in CSS3
New Elements & Features in CSS3New Elements & Features in CSS3
New Elements & Features in CSS3
 
Svcc 2013-css3-and-mobile
Svcc 2013-css3-and-mobileSvcc 2013-css3-and-mobile
Svcc 2013-css3-and-mobile
 
Css3
Css3Css3
Css3
 
Introduction to CSS3
Introduction to CSS3Introduction to CSS3
Introduction to CSS3
 
Making Your Own CSS Framework
Making Your Own CSS FrameworkMaking Your Own CSS Framework
Making Your Own CSS Framework
 

Semelhante a Vector vs Raster Graphics: SVG, Canvas, and CSS3 Options

SVG Strikes Back
SVG Strikes BackSVG Strikes Back
SVG Strikes BackMatt Baxter
 
Thats Not Flash?
Thats Not Flash?Thats Not Flash?
Thats Not Flash?Mike Wilcox
 
SVG vs Canvas - Showdown of the Painters
SVG vs Canvas - Showdown of the PaintersSVG vs Canvas - Showdown of the Painters
SVG vs Canvas - Showdown of the PaintersPhil Reither
 
Easy charting with
Easy charting withEasy charting with
Easy charting withMajor Ye
 
CANVAS vs SVG @ FrontInRio 2011
CANVAS vs SVG @ FrontInRio 2011CANVAS vs SVG @ FrontInRio 2011
CANVAS vs SVG @ FrontInRio 2011Davidson Fellipe
 
Visualizing Data with JavaScript and Canvas
Visualizing Data with JavaScript and CanvasVisualizing Data with JavaScript and Canvas
Visualizing Data with JavaScript and Canvasguestee8c59
 
Responsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and TechniquesResponsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and TechniquesVitaly Friedman
 
Make your own Print & Play card game using SVG and JavaScript
Make your own Print & Play card game using SVG and JavaScriptMake your own Print & Play card game using SVG and JavaScript
Make your own Print & Play card game using SVG and JavaScriptKevin Hakanson
 
Professional reports with SVG
Professional reports with SVGProfessional reports with SVG
Professional reports with SVGSpeedPartner GmbH
 
JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3Helder da Rocha
 
Visualizing data on web
Visualizing data on webVisualizing data on web
Visualizing data on webMatjaž Horvat
 
SVG Icons and Screen Reader Accessibility
SVG Icons and Screen Reader AccessibilitySVG Icons and Screen Reader Accessibility
SVG Icons and Screen Reader AccessibilityDennis Lembree
 
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSAbout Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSNaga Harish M
 

Semelhante a Vector vs Raster Graphics: SVG, Canvas, and CSS3 Options (20)

SVG Strikes Back
SVG Strikes BackSVG Strikes Back
SVG Strikes Back
 
Web Vector Graphics
Web Vector GraphicsWeb Vector Graphics
Web Vector Graphics
 
Thats Not Flash?
Thats Not Flash?Thats Not Flash?
Thats Not Flash?
 
SVG vs Canvas - Showdown of the Painters
SVG vs Canvas - Showdown of the PaintersSVG vs Canvas - Showdown of the Painters
SVG vs Canvas - Showdown of the Painters
 
Easy charting with
Easy charting withEasy charting with
Easy charting with
 
CANVAS vs SVG @ FrontInRio 2011
CANVAS vs SVG @ FrontInRio 2011CANVAS vs SVG @ FrontInRio 2011
CANVAS vs SVG @ FrontInRio 2011
 
Visualizing Data with JavaScript and Canvas
Visualizing Data with JavaScript and CanvasVisualizing Data with JavaScript and Canvas
Visualizing Data with JavaScript and Canvas
 
Svghtml5 Meetup
Svghtml5 MeetupSvghtml5 Meetup
Svghtml5 Meetup
 
Responsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and TechniquesResponsive Web Design: Clever Tips and Techniques
Responsive Web Design: Clever Tips and Techniques
 
Make your own Print & Play card game using SVG and JavaScript
Make your own Print & Play card game using SVG and JavaScriptMake your own Print & Play card game using SVG and JavaScript
Make your own Print & Play card game using SVG and JavaScript
 
Professional reports with SVG
Professional reports with SVGProfessional reports with SVG
Professional reports with SVG
 
JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3JavaONE 2012 Using Java with HTML5 and CSS3
JavaONE 2012 Using Java with HTML5 and CSS3
 
SVG and the web
SVG and the webSVG and the web
SVG and the web
 
Visualizing data on web
Visualizing data on webVisualizing data on web
Visualizing data on web
 
CSS and CSS3
CSS and CSS3CSS and CSS3
CSS and CSS3
 
SVG Icons and Screen Reader Accessibility
SVG Icons and Screen Reader AccessibilitySVG Icons and Screen Reader Accessibility
SVG Icons and Screen Reader Accessibility
 
SVG 101
SVG 101SVG 101
SVG 101
 
About Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JSAbout Best friends - HTML, CSS and JS
About Best friends - HTML, CSS and JS
 
pastel
pastelpastel
pastel
 
pastel
pastelpastel
pastel
 

Mais de Pascal Rettig

Web Typography for Front End Developers
Web Typography for Front End DevelopersWeb Typography for Front End Developers
Web Typography for Front End DevelopersPascal Rettig
 
The State of Front End Web Development 2011
The State of Front End Web Development 2011The State of Front End Web Development 2011
The State of Front End Web Development 2011Pascal Rettig
 
3D in the Browser via WebGL: It's Go Time
3D in the Browser via WebGL: It's Go Time 3D in the Browser via WebGL: It's Go Time
3D in the Browser via WebGL: It's Go Time Pascal Rettig
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript EverywherePascal Rettig
 
Cracking the Customer Acquisition Nut
Cracking the Customer Acquisition NutCracking the Customer Acquisition Nut
Cracking the Customer Acquisition NutPascal Rettig
 
HTML5 Space Invaders
HTML5 Space InvadersHTML5 Space Invaders
HTML5 Space InvadersPascal Rettig
 

Mais de Pascal Rettig (9)

Web Typography for Front End Developers
Web Typography for Front End DevelopersWeb Typography for Front End Developers
Web Typography for Front End Developers
 
Javascript FTW
Javascript FTWJavascript FTW
Javascript FTW
 
The State of Front End Web Development 2011
The State of Front End Web Development 2011The State of Front End Web Development 2011
The State of Front End Web Development 2011
 
Semantic chop
Semantic chopSemantic chop
Semantic chop
 
3D in the Browser via WebGL: It's Go Time
3D in the Browser via WebGL: It's Go Time 3D in the Browser via WebGL: It's Go Time
3D in the Browser via WebGL: It's Go Time
 
Mobile HTML5
Mobile HTML5Mobile HTML5
Mobile HTML5
 
Javascript Everywhere
Javascript EverywhereJavascript Everywhere
Javascript Everywhere
 
Cracking the Customer Acquisition Nut
Cracking the Customer Acquisition NutCracking the Customer Acquisition Nut
Cracking the Customer Acquisition Nut
 
HTML5 Space Invaders
HTML5 Space InvadersHTML5 Space Invaders
HTML5 Space Invaders
 

Último

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Último (20)

#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

Vector vs Raster Graphics: SVG, Canvas, and CSS3 Options

  • 1. Vector Graphics on the Web Pascal Rettig @cykod
  • 2. Vector vs. Raster Raster = Pixels = Bitmaps = .PNG, .JPEG ... Vector = Primitives = Shapes = .AI, .SVG Vectors can easily be “Rasterized” at a certain resolution into Bitmaps Rasters cannot easily be “Vectorized” without a whole lot of work
  • 3. Why do we care?
  • 4. Why do we care? • Designers often create as vectors anyway.
  • 5. Why do we care? • Designers often create as vectors anyway. • Resolution independent
  • 6. Why do we care? • Designers often create as vectors anyway. • Resolution independent • Smaller file size (when used appropriately)
  • 7. Why do we care? • Designers often create as vectors anyway. • Resolution independent • Smaller file size (when used appropriately) Hmm, sounds like they would be good for mobile...
  • 8. What are the options:
  • 9. What are the options: • Two W3C approved: SVG, Canvas
  • 10. What are the options: • Two W3C approved: SVG, Canvas • One “IE Special”: VML
  • 11. What are the options: • Two W3C approved: SVG, Canvas • One “IE Special”: VML • One “Sorta-kinda-vectorlike”: CSS3
  • 13. SVG • XML based format • SVG 1.1 W3C Recommendation since 2003 • Not something you generally write by hand - Create with Illustrator or Inkscape • Paths, Shapes, Fonts,Text, Fills, Gradients, Patterns,
  • 14. The Dream (not reality)
  • 15. The Dream (not reality) Use as an image: <img src=‘images/tiger.svgz’/>
  • 16. The Dream (not reality) Use as an image: <img src=‘images/tiger.svgz’/> or Embed Directly: <html xmlns:svg="http://www.w3.org/2000/svg"> ... <svg:svg width="300" height="100" version="1.1" > <svg:circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red" /> </svg:svg>
  • 18. The reality http://en.wikipedia.org/wiki/ Comparison_of_layout_engines_(Scalable_Vector_Graphics)
  • 20. The Reality (TL;DR) • Only Chrome, FF4 support gzipped SVG • Only Chrome, FF4 support HTML5 Direct Embedding • IE Support only coming in IE9
  • 21. The Solution? Use a library! SVG Web Use’s Native SVG or Flash You still write SVG files / data http://code.google.com/p/svgweb/ Raphael.js Uses Native SVG or VML Javascript API http://raphaeljs.com/
  • 22. SVG Web <script src="svg.js"></script> Then embed with an object tag or: <script type="image/svg+xml"> <svg width="400" height="300" id="svg11242"> ... </svg> </script> Scriptable from JavaScript pretty much normally
  • 23. Raphael.js var paper = Raphael(10, 50, 320, 200); var circle = paper.circle(50, 40, 10); circle.attr("fill", "#f00"); circle.attr("stroke", "#fff");
  • 24. Other Common uses Protovis - the graphing library you always wanted Cufon - font replacement with SVG/VML
  • 25. Attack Vector B: <canvas>
  • 26. HTML5 Canvas Tag • Standardized by the WHATWG (2007) • Grew out of WebKit (Dashboard Widgets) • Javascript interface to a bunch o’ Pixels
  • 28. Pixels? Where are the Vectors? <canvas> only stores pixel data. But, <canvas> has drawing primitives for: Rectangles, Lines, Quadtratic & Beizer Curves, Arcs, Fills, Text, Gradients... All drawing is done via a Javascript API
  • 29. Canvas Example <canvas id=”canvas” width=”150″ height=”150″> Your Browser don’t be supporting canvas </canvas> var canvas = document.getElementById(“canvas”); if (canvas.getContext) { var ctx = canvas.getContext(“2d”); ctx.fillStyle = “rgb(100,0,0)”; ctx.fillRect (0, 0, 100, 100); } https://developer.mozilla.org/en/ drawing_graphics_with_canvas
  • 30. Example #2: JS1K http://marijnhaverbeke.nl/js1k/ c=document.body.children[0];h=t=150;L=w=c.width=800;u=D=50;H=[];R=Math.random;for($ in C= c.getContext('2d'))C[$[J=X=Y=0]+($[6]||'')]=C[$];setInterval("if(D)for(x=405,i=y=I=0;i<1e4;)L= H[i++]=i<9|L<w&R()<.3?w:R()*u+80|0;$=++t%99-u;$=$*$/8+20;y+=Y;x+=y-H[(x+X)/u|0]>9?0:X;j=H[o= x/u|0];Y=y<j|Y<0?Y+1:(y=j,J?-10:0);with(C){A=function(c,x,y,r){r&&a(x,y,r,0,7,0);fillStyle=c.P ?c:'#'+'ceff99ff78f86eeaaffffd45333'.substr(c*3,3);f();ba()};for(D=Z=0;Z<21;Z++){Z<7&&A(Z%6,w/ 2,235,Z?250-15*Z:w);i=o-5+Z;S=x-i*u;B=S>9&S<41;ta(u-S,0);G=cL(0,T=H[i],0,T+9);T%6||(A(2,25,T-7 ,5),y^j||B&&(H[i]-=.1,I++));G.P=G.addColorStop;G.P(0,i%7?'#7e3':(i^o||y^T||(y=H[i]+=$/99), '#c7a'));G.P(1,'#ca6');i%4&&A(6,t/2%200,9,i%2?27:33);m(-6,h);qt(-6,T,3,T);l(47,T);qt(56,T,56, h);A(G);i%3?0:T<w?(A(G,33,T-15,10),fc(31,T-7,4,9)):(A(7,25,$,9),A(G,25,$,5),fc(24,$,2,h),D=B&y >$-9?1:D);ta(S-u,0)}A(6,u,y-9,11);A(5,M=u+X*.7,Q=y-9+Y/5,8);A(8,M,Q,5);fx(I+'¢',5,15)}D=y>h?1:D" ,u);onkeydown=onkeyup=function(e){E=e.type[5]?4:0;e=e.keyCode;J=e^38?J:E;X=e^37?e^39?X:E:-E}
  • 32. Canvas Reality... • No native IE support
  • 33. Canvas Reality... • No native IE support • Current browser implementations are slow
  • 35. Canvas Near future... • IE Support in IE9 (IE6-IE8 w/ excanvas.js)
  • 36. Canvas Near future... • IE Support in IE9 (IE6-IE8 w/ excanvas.js) • Next-gen browser support hardware- accelerated-awesomeness across the board
  • 37. Canvas Near future... • IE Support in IE9 (IE6-IE8 w/ excanvas.js) • Next-gen browser support hardware- accelerated-awesomeness across the board • WebGL support
  • 38. Canvas Status Q1 2010 Q4 2010 Q2 2011 Q4 2011
  • 40. CSS3 features that replace bitmap hacks: Rounded corners - *-border-radius Drop shadows: *-box-shadow Text Shadows: text-shadow Gradients: *-gradient Fonts: @font-face
  • 41. CSS3 Caveats You probably want to use a CSS Framework such as SASS/LESS to DRY the vendor prefixes. IE6-8 - fake it with http://css3pie.com/
  • 42. What also can be done: http://graphicpeel.com/cssiosicons
  • 43. How • Gradients, Rounded Corners, Shadows + • Borders • Rotations • Pseudo-elements • Transforms • Z-index Masking • A bunch of nested <div>’s
  • 44. A Good idea? Maybe. • CSS3 Icons probably not worth the markup complexity. • But a re-scalable pure CSS logo... http://www.csstemplateheaven.com/articlestutorials/pure- css3-logo/
  • 45. So SVG or Canvas?
  • 49. SVG vs. Canvas SVG Canvas Persistent Scene Graph Hover, Click Events Browser does the work
  • 50. SVG vs. Canvas SVG Canvas Persistent Scene Graph Just Pixels (can R/W) Hover, Click Events Own Event calculations Browser does the work Full canvas refresh
  • 51. Bonus
  • 52. Yo Dawg, I heard you like vector graphics... http://burst.bocoup.com/
  • 53. Yo Dawg, I heard you like vector graphics... So I put SVG in your Canvas so you could animate while you rasterize. http://burst.bocoup.com/
  • 54. Yo Dawg, I heard you like vector graphics... So I put SVG in your Canvas so you could animate while you rasterize. http://burst.bocoup.com/

Notas do Editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n