Skip navigation
Help

vector graphics

The iPad may have started it, but the high resolution screen will soon be the norm. Photo: Ariel Zambelich/Wired.com

The rise of high-resolution screens means that web developers need resolution-independent graphics or images look blurry. For photographs responsive images may be the solution, but for simpler graphics like logos and icons there’s an easy solution that’s been with us for some time — Scalable Vector Graphics or SVG.

A slightly blurry icon or logo on a retina display probably isn’t going to drive your visitors away, but if it’s easy to fix and can potentially save you some bandwidth as well, why not?

Historically, browser support for SVG has not been particularly good, but these days SVG images work just about everywhere, except older versions of IE. Thankfully it isn’t hard to serve up regular old PNG files to older versions of IE while keeping the resolution-independent goodness for everyone else.

Developer David Bushell recently tackled the topic of SVG graphics in a very thorough post titled A Primer to Front-end SVG Hacking. Bushell covers using SVG graphics in image tags, stylesheets, sprites and even the old-school <object> method. He’s also got a great list of external resources, including SVGeezy for IE fallback, the SVG Optimizer for saving on bandwidth and grunticon which converts SVG files to PNG and data URIs for fallback images.

Head on over to Bushell’s site for more details and you can check out some of our previous posts on SVG for even more resources.

0
Your rating: None

An image displayed on a computer after it was successfully commandeered by Pinkie Pie during the first Pwnium competition in March.

Dan Goodin

A hacker who goes by "Pinkie Pie" has once again subverted the security of Google's Chrome browser, a feat that fetched him a $60,000 prize and resulted in a security update to fix underlying vulnerabilities.

Ars readers may recall Pinkie Pie from earlier this year, when he pierced Chrome's vaunted security defenses at the first installment of Pwnium, a Google-sponsored contest that offered $1 million in prizes to people who successfully hacked the browser. At the time a little-known reverse engineer of just 19 years, Pinkie Pie stitched together at least six different bug exploits to bypass an elaborate defense perimeter designed by an army of some of the best software engineers in the world.

At the second installment of Pwnium, which wrapped up on Tuesday at the Hack in the Box 2012 security conference in Kuala Lumpur, Pinkie Pie did it again. This time, his attack exploited two vulnerabilities. The first, against Scalable Vector Graphics functions in Chrome's WebKit browser engine, allowed him to compromise the renderer process, according to a synopsis provided by Google software engineer Chris Evans.

Read 5 remaining paragraphs | Comments

0
Your rating: None

  

“So, you do nothing all day.”

That’s how many people would respond to someone who says they spend the day with a pen or pencil in their hand. It’s often considered an empty practice, a waste of time. They’re seen as an empty mind puttering along with the busy work of scribbling.

But for us designers and artists, drawing pictures all day is integral to our process and to who we are as creative people, and despite the idea that those who doodle waste time, we still get our work done. So, then, why are those of us who draw pictures all day even tempted to think that someone who is doodling or drawing pictures in a meeting or lecture is not paying attention?

What does it mean to be a doodler, to draw pictures all day? Why do we doodle? Most of all, what does it mean to our work? It turns out that the simple act of scribbling on a page helps us think, remember and learn.

What Does It Mean To Doodle?

The dictionary defines “doodle” as a verb (“scribble absentmindedly”) and as a noun (“a rough drawing made absentmindedly”). It also offers the origins of the word “doodler” as “a noun denoting a fool, later as a verb in the sense ‘make a fool of, cheat.’”

But the author Sunni Brown offers my favorite definition of “doodle” in her TED talk, “Doodlers, unite!”:

“In the 17th century, a doodle was a simpleton or a fool, as in “Yankee Doodle.” In the 18th century, it became a verb, and it meant to swindle or ridicule or to make fun of someone. In the 19th century, it was a corrupt politician. And today, we have what is perhaps our most offensive definition, at least to me, which is the following: “To doodle officially means to dawdle, to dilly dally, to monkey around, to make meaningless marks, to do something of little value, substance or import and,” my personal favorite, “to do nothing.” No wonder people are averse to doodling at work. Doing nothing at work is akin to masturbating at work. It’s totally inappropriate.”

It is no wonder, then, why most people do not have great expectations of those who “draw pictures all day.” Or perhaps they are inclined to think that those who draw pictures all day are not highly intellectual and are tempted to say to them condescendingly, “Go and draw some of your pictures.” As designers, many of us have heard such comments, or at least felt them implied, simply because we think, express or do things differently.

Why Do We Doodle?

Consider that even before a child can speak, they can draw pictures. It is part of their process of understanding what’s around them. They draw not just what they see, but how they view the world. The drawing or doodle of a child is not necessarily an attempt to reflect reality, but rather an attempt to communicate their understanding of it. This is no surprise because playing, trial and error, is a child’s primary method of learning. A child is not concerned with the impressions that others get based on their drawings or mistakes.

An Example of a doodle
An example of a doodle.

Their constant drawing, picture-making and doodling is a child’s way of expressing their ideas and showing their perceptions in visual form. It comes from a need to give physical form to one’s thoughts. Similarly, an adult doodles in order to visualize the ideas in their head so that they can interact with those ideas.

Visual Learners

According to Linda Silverman, director of both the Institute for the Study of Advanced Development and the Gifted Development Center and author of Upside-Down Brilliance: The Visual-Spatial Learner, 37% of the population are visual learners. If so many people learn better visually, we can expect, then, that some of them learn better by putting a speech, lecture or meeting into visual and tangible form through pictures or doodles, rather than by being provided with pictures or doodles (which would be the product of another person’s mind).

37% of the population are visual learners

Humans have always had a desire to visually represent what’s in their minds and memory and to communicate those ideas with others. Early cave paintings were a means of interacting with others, allowing an idea or mental image to move from one person’s mind to another’s. The purpose of visual language has always been to communicate ideas to others.

Secondly, we doodle because our brain is designed to empathize with the world around us. According to Carol Jeffers, professor at California State University, our brains are wired to respond to, interact with, imitate and mirror behavior. In an article she wrote, she explains the recent research into “mirror neurons” which help us understand and empathize with the world around us.

A cave painting
Cave paintings were our first means of communicating ideas to others.

Think of it this way. When you’re at an art gallery and find a painting that intrigues you, what is your first reaction? You want to touch it, don’t you? I thought so.

When I was a ballroom dancer, I used to sit and watch those who I considered to be great dancers, tracing their forms in space with my index finger as a way to commit them to memory. I used to go to galleries and museums and, at a distance, trace the lines and forms that I saw in the paintings and designs. I did this out of curiosity and a desire to physically record what I saw to memory.

Nearly 100 years ago, Maria Montessori discovered the link between physical touch and movement and learning in children. Montessori education teaches children to trace the letters of the alphabet with their index finger as a way to commit their shapes to memory. My son used to trace forms that he found interesting in space. It’s safe to say, then, that we doodle to visually commit to memory a concept that we want to both empathize and interact with.

An experiment conducted by Jackie Andrade, professor of psychology at the University of Plymouth in England, demonstrated the positive effect that doodling has on memory retention. In the experiment, 40 people were given a simple set of instructions to take RSVP information over the phone from people going to a party. The group of 40 was divided in two. One group of 20 was told to doodle (limited to shading in order not to emphasize the quality of the doodles), and the other 20 would not doodle.

The doodlers recalled 29% more information.

Doodling a lightbulb
Doodling helps us retain information.

The study showed that doodling helps the brain to focus. It keeps the mind from wandering away from whatever is happening, whether it’s a lecture, reading or conference talk.

Still, we have become bored with learning.

Professor Emeritus at Cornell University, Joseph D. Novak argues that this is because we have been taught to memorize but not to evaluate the information being given to us. In many traditional settings, the pattern is simple and dull: sit, receive and memorize. Many traditional educational systems do not encourage active engagement with the material. Doodling, drawing and even making diagrams helps us not only engage with the material, but also identify the underlying structure of the argument, while also connecting concepts in a tactile and visual way. Jesse Berg, president of The Visual Leap, pointed out to me in a conversation that doodling is a multisensory activity. While our hand is creating what might seem to be random pictures, our brain is processing the stimuli that’s running through it.

Many of us are the product of traditional schooling, in which we were made to numbingly memorize dates and facts, and many of us continue this pattern later in life. While some of us were avid doodlers (I used to fill the backs of my notebooks with pictures and draw on desks with a pencil during class), some of us stopped at high school, others in college and others once we settled into a job. At some point during the education process, doodling was discouraged. Teachers most likely viewed it as a sign of inattentiveness and disrespect. After hard preparation, educators want nothing more than unwavering attention to their lectures. The irony is that, according to Andrade’s study, doodlers pay more attention to the words of educators than we think.

In her TED talk, Sunny Brown goes on to explain the benefits of doodling and even offers an alternative to the definition found in the Oxford Dictionary:

“Doodling is really to make spontaneous marks to help yourself think. That is why millions of people doodle. Here’s another interesting truth about the doodle: People who doodle when they’re exposed to verbal information retain more of that information than their non-doodling counterparts. We think doodling is something you do when you lose focus, but in reality, it is a preemptive measure to stop you from losing focus. Additionally, it has a profound effect on creative problem-solving and deep information processing.”

How Can Designers Use This To Their Benefit?

As designers, we have a unique advantage when it comes to doodling. We don’t just doodle to keep our minds focused — we also deliberately sketch ideas in order to problem solve and to get immediate feedback from clients and peers. Designers such as Craighton Berman and Eva-Lotta Lamm are two of the biggest proponents of the “sketchnotating” movement. Berman states that sketchnotating “forces you to listen to the lecture, synthesize what’s being expressed, and visualize a composition that captures the idea — all in real time.”

In 2009, I came across a book titled The Back of the Napkin by Dan Roam. Roam is a business strategist and founder of Digital Roam, a management-consulting firm that uses visual thinking to solve complex problems. He uses a simple approach to solving problems visually. Every idea is run through five basic questions to encourage engaged thinking and to ensure a meaningful meeting. The process takes the acronym SQVI^. S is for simple or elaborate, Q is for qualitative or quantitative, V is for vision or execution, I is for individual or comparison, and ^ is for change or status quo. These simple choices are worked through with simple doodles in order to better understand the problem and find a solution. In his book, Roam says:

“What if there was a way to more quickly look at problems, more intuitively understand them, more confidently address them, and more rapidly convey to others what we’ve discovered? What if there was a way to make business problem solving more efficient, more effective, and — as much as I hate to say it — perhaps even more fun? There is. It’s called visual thinking, and it’s what this book is all about: solving problems with pictures.”

After discovering Roam’s book, I decided to doodle again. Once a prolific doodler and drawer, I had become inactive in lectures and similar settings, often forgetting what was said. Taking notes felt too cumbersome, and I often missed words and ideas. I decided to give doodling another shot. Instead of focusing on specifics, I would focus on concepts, key words and ideas.

Since 2011, I have been actively promoting doodling in my design classes, making a deal with my students, saying to them, “Doodle to your heart’s content, but in return I want you to doodle the content of my lectures.” They are skeptical at first, but they soon realize that doodling is better than having a quiz. I reap the benefits of doodling, and by allowing them to doodle — with the requirement that it be based on the class’ content — they become more informed of the topic and they engage in more meaningful conversations about design.

A sketchbook
A designer’s best friend: a sketchpad.

The typographic novices in my classes naturally start to apply the principles of visual hierarchy and organization, grouping ideas either by importance or by category. They will group ideas with lines, boxes, marks and more. Headings and lecture titles might be made larger, more ornate or bolder, and key concepts might be visually punctuated. It is fascinating how natural and almost second-nature the idea of visual hierarchy is to all of us. The learning curve of typography is steep for some of us, but doodling and sketchnotating really makes it easier to grasp. Below are some doodles by students in my classes.

Introduction to Typography lecture doodle by Alisa Roberts
Doodle by Alisa Roberts from my “Introduction to Typography” course.

By picking out concepts, ideas and topics, the students start to establish a hierarchy by making visual groupings and start to use visual punctuation. By the time I assign work on typographic hierarchy, the sketches tend to show more astuteness. Transferring these sketches to the computer is a challenge for those new to typography, but once they naturally understand the relationships in what they are doing, they start to make smarter design decisions.

Identity and Branding class lecture doodle by Aubrie Lamb
Doodle by Aubrie Lamb from my “Identity and Branding” course.

Identity and Branding class lecture doodle by Aubrie Lamb
Another by Aubrie Lamb from the same course.

As we have seen, doodling has many benefits, beyond what designers as visual communicators and problem solvers use it for. Doodling also helps our brain function and process data. Those of us who doodle should do so without feeling guilty or ashamed. We are in good company. Historically, doodlers have included presidents, business moguls and accomplished writers. Designer, educator and speaker Jason Santa Maria says this:

“Sketchbooks are not about being a good artist. They’re about being a good thinker.”

Doodling, drawing pictures and sketchnotating are about using visual skills to solve problems, to understand our world and to respond effectively. So, what are you waiting for? Doodle!

Further Reading

Unless otherwise stated, images are from Stock.XCHNG.

(al) (il)

© Alma Hoffmann for Smashing Magazine, 2012.

0
Your rating: None


The above two-month old trailer of Dark Computer Enterainment's Vektropolis made the rounds this month thanks to Pixel Prospector originally, charming gamers with its classy 80s arcade vector style. IndieGames caught up with developer Frank Travaini to find out the latest on his team's retro rescue game/first person shooter.

"[The above] video shows us playing around with just some of the features, but it's still very much a tech demo at that point. Andrew Crawshaw's been working on fine tuning the challenge of the game, and trying to tie together as much of our feature set as we can in a way that make sense but most of all is going to be fun. The video might make it look like an out and out shooter, but there's going to be a strategic element, too."

Lead Vektropolis developer Daniel Gallagher is no stranger to 80s vector graphics, seeing as he co-founded Vektor Grafix, which ported the 1983 Star Wars arcade game to several platforms.

Travaini shares that Gallagher's "been refining the surviving features; make the buildings look more elegant, improving the flight controls, and the not inconsiderable task of creating a brand new AI system so that the enemies can work their way around our cities like seasoned taxi drivers. A game like Vektropolis is full of technical hurdles to overcome, but we're ticking them off at a healthy rate."

As for the game's present look, Travaini notes, "Right now absolutely all of the artwork in the game is still being generated by Danny's code, but we're looking at modelling the enemies in 3D packages and bringing them into the game."

What's an 80s vector style game without a sci-fi story? Travaini reassures, "It's kind of crazy, but completely fits with what we're trying to achieve with the gameplay. People are going to think it's awesome, or they're going to be saying WTF?"

Travaini says the team is open to all platforms. "We had some good interest from publishers; however, we are really waiting for the demo to be out before making a decision about self-financing the game, Kickstarter or sell." This demo, Travaini urges, will only go out to select members of the press (and publishers) in the next month and will not have final graphics, art or a story line in place.

Travaini passed along these current WIP photos to IndieGames, so you could see it a little clearer than in the video:

Vektropolis_WiP_IndieGamesCom_03.jpg

Vektropolis_WiP_IndieGamesCom_04.jpg

Vektropolis_WiP_IndieGamesCom_06.jpg
For more photos, check out the game's official Twitter collection.

0
Your rating: None

The high-res future is coming

The first of the new iPads will arrive in the hands of the public this Friday, March 16. Like the iPhone before it, and no doubt many more devices to come after it, the new iPad has four times the resolution of typical screens. That means your visitors will soon be looking at your site on a high-resolution screen with a whopping 3.1 million pixels.

The sharp, crystal-clear screens are awesome news for new iPad owners, but they create some new dilemmas for web developers who’d like to offer a better experience for high-resolution screens. Sure, increased pixel density means you can serve up sharper, better looking graphics, but there is a cost as well — bigger images mean more bandwidth and longer page loads.

This isn’t a new problem by any means and Webmonkey has looked at a variety of solutions in the past, including techniques like adaptive images and responsive images.

The problem is simple: you need to send smaller images to small screens and larger images to larger screens. Sending a huge iPad-optimized image to a device with a max resolution of 320×480 just doesn’t make sense. At the same time, when bandwidth isn’t an issue, most sites will want to serve high-resolution content to displays that can handle it.

The ideal solution would be to detect both the resolution of the screen and the available bandwidth. Then, based on the combination of those two factors, the server could offer up the appropriate image. Currently that’s not possible, though there are already proposals to extend HTML to handle that scenario.

The Responsive Image Working Group is a W3C community group hoping to solve some of these problems. The group is proposing a new HTML element, <picture>, which will take into account factors like network speed, device dimensions, screen pixel density and browser cache to figure out which image to serve up. Think of it as a much smarter version of the old lowsrc property. So far though it’s all hypothetical

In the mean time if you’d like to serve up high resolution images to your third-generation iPad visitors look no further than Apple.com for one (not necessarily ideal) way to do it. An Apple Insider reader noticed that Apple is already prepping its site to deliver double-resolution images to new iPads. Cloud Four’s Jason Grigsby, whose responsive image research we’ve covered before, has a great breakdown of what Apple is doing.

Essentially Apple is serving up lower resolution images by default, then using JavaScript to send larger images on to iPads. That works, but it will definitely mean increased download times for new iPads since they have to download two files for every graphic. Apple’s approach will also up the number of HTTP requests, which will also slow down the page.

The slower page loads seem to be an acceptable trade off for Apple since the company no doubt wants to showcase the new iPad’s high resolution display with high resolution images. For other sites the bandwidth trade off may not be worth the gain in image resolution.

Still, screens are only going to continue getting better with ever-increasing pixel density. Now is the time, if you haven’t already, to start embracing CSS 3 (avoid images altogether with gradients, shadows and rounded corners in CSS 3), Scalable Vector Graphics (SVG) for resolution independent graphics and of course @media queries to serve high-res background images.

For more on detecting and developing for high resolution displays, check out these posts from around the web:

0
Your rating: None

New submitter GrantRobertson writes with a question about quickly developing prototypes for new interface design concepts "My research/tinkering will be along two main lines: (1) Devising entirely new graphical user interface elements, mostly in 2D, though often in a true or simulated 3-D space. I am working on ways to visualize, navigate, and manipulate very, VERY large data-sets of academic research information. (2) Computer based education software, though of a type never seen before. This will combine some of the GUI elements invented in (1) as well as displaying standard HTML or HTML5 content via a browser engine My requirements are: (A) A decent IDE ecosystem; (B) A decent set of libraries, but ones that don't lock me in to a particular mind-set like Swing does in Java. (Boxes in boxes in boxes, Oh My!); (C) An ability to easily draw what I want, where I want and make any surface of that 3D object become a source for capturing events; (D) Ease of cross-platform use. (So others can easily look at my examples and run with them.); (E) No impediments to open-source licensing my code or for others to go commercial with it either (as I have seen when I looked into Qt). So, should I just stick with Java and start looking outside the box for GUI toolkits? Or is there something else out there I should be looking at?"

I'm not sure what impediments Qt has to proprietization of software since it's LGPL nowadays; in any case, Qt Quick and GNOME's Clutter seem like they could be a useful. Read on for more context.


Share on Google+

Read more of this story at Slashdot.

0
Your rating: None

  

In this article, we’ll look at Scalable Vector Graphics (SVG), one of the most underused technologies in website development today.

Before diving into an example, let’s consider the state of the Web at present and where it is going. Website design has found new vigor in recent years, with the evolving technique of responsive design. And for good reason: essentially, responsive website design moves us away from the fixed-width pages we’ve grown accustomed to, replacing them with shape-shifting layouts and intelligent reflowing of content. Add to that a thoughtful content strategy and mobile-first approach, and we’re starting to offer an experience that adapts across devices and browsers to suit the user’s context.

When we look at the breadth of Web-enabled devices, responsive design is sure to provide a better user experience. Scrolling horizontally, panning and zooming the viewport have their place in user interface design, but forcing the user to do these things just to navigate a website quickly becomes tedious. Fitting the website to the viewport is about more than just layout: it’s also about resolution. In this article, I’ll demonstrate why SVG is a perfect addition to future-friendly Web development.

Introducing SVG

SVG offers a truly resolution-independent technique for presenting graphics on the Web. SVG is a vector graphics format that uses XML to define basic properties such as paths, shapes, fonts and colors, and more advanced features such as gradients, filters, scripting and animation. Create the file once and use it anywhere, at any scale and resolution.

Consider the use cases: UI and navigation icons, vector-style illustrations, patterns and repeating backgrounds. For all of these, a scalable graphic is the perfect solution from a visual standpoint, and yet fixed-resolution images are still the norm. In the example below, we’ll show you how to expand on a common development technique to take advantage of SVG.

Resolution independence with SVG

A Case Study: CSS Sprites

We all know about the CSS sprites technique. (If you don’t, then have a quick read through Sven Lennartz’ article. And Louis Lazaris points out its pros and cons.) In the example below, we’ll show how seamlessly SVG replaces normal raster images. If this technique is not for you, you can certainly imagine a whole array of similar situations in which to use SVG.

Vector icons play a big role in user interface design. Pictures express concepts with vivid clarity, whereas their textual counterparts might carry ambiguity. In UI design, where space is scarce, a simple illustrated icon could be greatly welcome.

I’ve mocked up the following example:

An icon based UI menu

I’ll be first to admit that this row of icons won’t win any design awards, but it will suffice for the sake of this article! Let’s look at the HTML:

<div class="actions">
   <a class="a-share" href="#">Share</a>
   <a class="a-print" href="#">Print</a>
   <a class="a-tag" href="#">Tag</a>
   <a class="a-delete" href="#">Delete</a>
</div>

I’ve kept the HTML to a minimum for clarity, but in practice you’d probably want to mark it up with an unordered list. And you’ll almost certainly want to replace those hashes with real URLs (even if JavaScript provides the functionality, having a fallback is nice). Let’s look at the CSS:

.actions {
   display: block;
   overflow: auto;
}

.actions a {
   background-image: url('sprite.png');
   background-repeat: no-repeat;
   background-color: #ccc;
   border-radius: 5px;
   display: block;
   float: left;
   color: #444;
   font-size: 16px;
   font-weight: bold;
   line-height: 20px;
   text-decoration: none;
   text-shadow: 0 -1px 2px #fff;
   padding: 10px 20px 10px 40px;
   margin-right: 5px;
}

.a-share  { background-position: 10px 0; }
.a-print  { background-position: 10px -40px; }
.a-tag    { background-position: 10px -80px; }
.a-delete { background-position: 10px -120px; }

Note the fixed-pixel sizing and the PNG background, which we can see below framed in full Photoshop production glory:

A PNG sprite in Photoshop

This implementation of a CSS sprite is basic, and at today’s standard, it’s not good enough! How can we enhance this? First, let’s consider the following issues:

  1. We’ve rasterized the image at a very early stage. Even at full size, icons in which points sit between pixels, such as the one for “Print,” have blurred.
  2. If we zoom in, the image will blur or pixellate even more; there is no additional data to re-render the image at larger sizes.
  3. Everything has a fixed size, which is neither good for responsive design nor good for accessibility, because the browser’s default font size is ignored.

As you’ve probably guessed by now, we’ll show you how SVG solves these problems. But first, let’s reiterate each point thoroughly to understand the issues at large.

1. Rasterization

Devices such as modern smartphones have a very high pixel density; some already surpass the 300 pixels-per-inch (PPI) mark that is assumed to be the limit of the human eye’s ability to distinguish fine details. A pixel has no real-world equivalent in size until it sits on a screen of fixed dimension (say, 3.5 inches diagonally) and fixed resolution (say, 640 × 960 pixels). At this scale, text with a font size of 16 pixels would be incredibly small to the eye. For this reason, devices simply cannot translate 1 CSS pixel unit to 1 device pixel; instead, they double up. Thus, a 16-pixel font size actually takes over 32 pixels when rendered.

The same applies to images; but they are already rasterized, so doubling up the pixels has no benefit. In our example, each icon has been rasterized at around 25 × 25 pixels (the whole sprite being 30 × 160), so they cannot take advantage of the double pixel ratio. One solution is to use CSS media queries to detect the pixel ratio. This is already implemented in Webkit- and Gecko-based browsers.

To improve our example, we can add the following CSS declaration:

@media only screen and (-webkit-min-device-pixel-ratio: 2)  {
   .actions a {
      background-image: url('sprite@2x.png');
      background-size: 30px 160px;
   }
}

The alternate background image supplied in the code above has been saved at 60 × 320 pixels (i.e. double the original dimensions). The background-size property tells CSS to treat it smaller. Significantly, now the device has the additional data to render a better image (if capable).

This solution isn’t bad, but it doesn’t solve the problems we’ll run into in points 2 and 3 below. It also requires that we maintain multiple files of increasing size: a potential burden on bandwidth and a real hassle. For non-vector images, such as photography in JPG format, we can’t do much more than that.

2. Zooming

At their default size, our rasterized icons look acceptable, at least on low-pixel-density screens. However, should the user zoom in on the Web page, these little UI delights will degrade very quickly.

A PNG sprite zoomed in and blurred.

Zooming is a common action when users find a website too small for comfortable viewing. Or, to put it another way, websites that are designed too small are very common. There is really no “perfect” size, because almost everyone has at least some level of visual impairment, since our eyes inevitably deteriorate with age. Secondly, with the rapid increase in touchscreen devices, pinch-to-zoom has become the standard way to enlarge fixed-sized content designed for larger screens (i.e. much of the Web today).

We should develop websites in a way that minimizes the need for user input — that’s where responsive design comes in (see point 3 below) — but zooming is here to stay. There’s simply no way to provide pre-rasterized images for every level of zoom (in theory, an infinite scale). Scalable graphics are the solution, and we’ll show you how to enhance our example. But first, a related word on fixed sizing.

3. Fixed Sizes

Presenting page elements at fixed sizes forces many users to zoom, but it also disables a very useful browser feature. Users can set their preferred font size (the default in browsers is 16 pixels). By sizing everything in pixels, we override this preference. Sizing elements based on this default is much better, so that, if the text is bigger, everything adjusts to match. This essentially mimics the zooming effect but happens without the user having to manually do it on every visit. Ethan Marcotte has written a great article that explains relative font sizes.

Let’s re-implement our sprite example with a solution to these three issues.

A Scalable Implementation

Here is the HTML again. We don’t need to change anything here.

<div class="actions">
   <a class="a-share" href="#">Share</a>
   <a class="a-print" href="#">Print</a>
   <a class="a-tag" href="#">Tag</a>
   <a class="a-delete" href="#">Delete</a>
</div>

The updated CSS is where the magic happens:

body { font-size: 100%; }

.actions {
   display: block;
   overflow: auto;
}

.actions a {
   font-size: 1em;
   line-height: 1.25em;
   padding: 0.625em 1.25em 0.625em 2.5em;
   margin-right: 0.3125em;
   border-radius: 0.3125em;
   background-image: url('sprite.svg');
   -webkit-background-size: 1.875em 10em;
   -o-background-size: 1.875em 10em;
   -moz-background-size: 1.875em 10em;
   background-size: 1.875em 10em;
   /* styles carried over from the original implementation */
   background-repeat: no-repeat;
   background-color: #ccc;
   color: #444;
   display: block;
   float: left;
   text-decoration: none;
   text-shadow: 0 -1px 2px #fff;
}

.actions-em .a-share { background-position: 0.625em 0; }
.actions-em .a-print { background-position: 0.625em -2.5em;  }
.actions-em .a-tag { background-position: 0.625em -5.0em;  }
.actions-em .a-delete { background-position: 0.625em -7.5em;  }

In this version, we’ve made the following changes:

  • The background-image is now an SVG file.
  • All sizes are based on the default of 16 pixels, or 1 em. If the user’s default is larger or smaller, then everything will scale relatively. (If you multiple each em size by 16, you’ll get the number of pixels used in our initial fixed-size example.)
  • The background-size is very important. By setting this in em units, we’re telling the browser to scale the sprite relative to everything else. You’ll notice that 1.875 × 10 em multiplied by 16 becomes 30 × 160 — the base size at which we produced the sprite in pixels.
  • The background-position of each sprited icon is also based on relative units.

Now that we’re using SVG and relative sizes, we have solved the three big issues highlighted above. A scalable graphic can be rasterized on demand to perfectly suit any device resolution and any zoom level. By using relative sizes, we can continue implementing a responsive design, minimizing as much as possible the need for the user to zoom. We’re also respecting the browser’s default font size, and enabling our design to adapt accordingly.

I actually produced the SVG sprite first and the PNG version from that. (I imported the SVG in Photoshop before exporting it as a PNG — Illustrator’s PNG export had very poor rasterization.) Below is the header in my SVG file. Notice the same 30 × 160 initial size.

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
   width="30px" height="160px" viewBox="0 0 30 160" enable-background="new 0 0 30 160" xml:space="preserve">

You can see that the attributes for width and height are set in pixels (width="30px" height="160px") in the opening svg tag (as generated by Adobe Illustrator). This actually causes it to render early in Firefox, before the graphic has scaled to match the em sizes in background-size. Webkit-based browsers seem to scale the SVG perfectly, regardless. I’ve found that editing the SVG file to use em units in these two attributes fixes any rendering issues in Firefox.

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
   width="30em" height="160em" viewBox="0 0 30 160" enable-background="new 0 0 30 160" xml:space="preserve">

I don’t know which browser actually implements this scaling correctly, but let it be noted that extra care is needed to ensure cross-browser perfection. Mozilla MDN has an excellent in-depth article, “Scaling of SVG Backgrounds,” which explores more practical examples. For more ideas, see Alex Walker’s article “A Farewell to CSS3 Gradients.”

Here’s a super-close screenshot showing the SVG sprite:

A close-up of a SVG sprite.

The sprite scales beautifully. (Sadly, the same can’t be said for my tacky text-shadow effect.)

It’s best to experience the joys of scalable graphics and relative sizing firsthand. I’ve uploaded a side-by-side live demo demonstrating a combination of all the techniques mentioned above.

Browser Support

At the start of this article, I said that SVG was underused. I believe that has generally been the case due to poor browser support. But things are different now! Browser support for SVG has blossomed over the last year to the point where implementing it is a viable use of development time.

According to the website When Can I Use?, support for SVG across multiple implementations is as follows (I’ve combined support for both CSS’ background-image and HTML’s img source — the most useful attributes):

  • Internet Explorer 9+
  • Firefox 4+
  • Chrome 4+
  • Safari 4+
  • Opera 9.5+

Mobile browser support is also pretty much across the board. If a workable fallback exists for older browsers, then SVG is a very viable solution.

For some of the new additions to Web standards, we can implement them safe in the knowledge that old browsers will simply ignore them and that they aren’t even required. We call this “progressive enhancement”: better browsers get a progressively better experience. SVG is slightly different, because for most practical purposes, it simply replaces other images in CSS backgrounds and HTML elements. The image format — be it SVG, PNG, JPG or GIF — is either supported or it isn’t. We can’t simply follow the practice of progressive enhancement here, because an image failing to render is not an acceptable experience.

Browser Sniffing or Feature Detection?

We could make an educated guess and say that we need to worry only about users of Internet Explorer 6 to 8. In this case, the conditional comments technique for IE-only styles enable us to re-apply a second CSS background-image of a supported format such as PNG, instead of the default SVG background.

Browsing sniffing is always a dangerous game. While Internet Explorer tends to be the main offender, we can never assume it is the only one.

The safer and highly recommended option is to detect SVG support and use it only if it’s found. I suggest using Modernizr if you need to detect multiple features. Modernizr applies a class of svg to your root html element if detected (to which you can apply SVG as a background-image). If you’re using SVG as the source of an image element in HTML, then implementation is a little harder. You’ll have to write more JavaScript to find and replace all sources once support has been established.

The problem with these methods is that the browser will download the fallback image before SVG is detected — the only exception being the conditional comments technique for IE. Users will also likely see a flash of re-styled content when the source image changes. This shouldn’t be the case for long; but at least for now, these problems may be enough to hold you off on SVG usage.

File Size

In our sprite example, the raw SVG file was 2445 bytes. The PNG version was only 1064 bytes, and the double-sized PNG for double-pixel ratio devices was 1932 bytes. On first appearance, the vector file loses on all accounts, but for larger images, the raster version more quickly escalates in size.

SVG files are also human-readable due to being in XML format. They generally comprise a very limited range of characters, which means they can be heavily Gzip-compressed when sent over HTTP. This means that the actual download size is many times smaller than the raw file — easily beyond 30%, probably a lot more. Raster image formats such as PNG and JPG are already compressed to their fullest extent.

Performance

Rendering performance is a concern with SVG, especially on mobile devices, whose hardware is limited. Raster images can be rendered pixel for pixel after decompression and de-encoding. Vector graphics need to be rasterized at a specific resolution every time they’re viewed.

SVG has consistently proved slower than Canvas as a platform for animating vector graphics; but our concern here is basic rendering, not manipulation a thousand times per second, and if that is possible, then simple rendering shouldn’t be a concern. The more intensive SVG features are things like clipping masks and filter effects. These are unnecessary for many practical purposes (like our sprite example), but, if required, the best way to check performance is by testing. A lot of Web development is supported in theory, but in practice results are far from perfect.

Alternative Methods

Hopefully you agree that SVG is extremely useful but not always the ideal solution to resolution independence. Ultimately, the trick is to avoid raster images while maintaining the scalability of visual styles. Below are a few more ideas to think about.

CSS3

You’ve probably already started combining CSS3 properties such as linear-gradient, text-shadow and box-shadow to create more complex styles. Web developer Lea Verou curates a CSS3 pattern gallery that shows off the impressive potential of gradients alone.

CSS3 gradient patterns

In his article “Mobile Web in High Resolution,” Brad Birdsall introduces a technique to maintain pixel perfection for high-resolution displays using the pixel-ratio property.

Then there are pure CSS “icons,” which Faruk Ateş rightly points out as being absolute “madness” — certainly so if you’re using CSS to create a logo! But you could argue the benefits of a small handful of very specific techniques, such as CSS triangles, as demoed by Chris Coyier.

Web Fonts

Dingbat Web fonts and look-a-like Unicode glyphs are two interesting alternatives for vector icons, both with accessibility and semantic challenges. Jon Hicks has a write-up of perhaps the best practice for this. SVG seems a more appropriate technique for icons, but both have an immediate visual impact at high resolutions — and we’ll be paying increasing attention to that in coming years.

Looking Forward

As you can see, SVG usage is very much a possibility, and browser support and performance will only improve in future. What’s important to note from this article is that we really should be building websites that are as resolution-independent as possible.

Consider the “one Web” philosophy and the vast range of devices we use to access it — there is no single user experience. The more we can do to stay device-agnostic, the better. Responsive website design addresses many of these needs and certainly provides many benefits. Using vector graphics may not be as apparent, but its little improvements really do make a difference.

With today’s level of support, many users can experience the beauty of crisp scalable graphics… or perhaps that’s the wrong way to think about it. Most users won’t say “Wow! Kudos on the vectors.” To our dismay, they probably wouldn’t even consider them (and certainly wouldn’t recognize the effort required to craft them). And that’s a good thing; each time we improve the user’s experience, we don’t necessarily need to make a song and dance about it. Letting things continue to grind away under-appreciated is OK. It’s the lack of such things that gets recognized and sniffed at. Raise the user’s expectations in visual aesthetics, and they’ll start to notice the websites that do look shoddy. If you don’t do it, others will.

(al)

© dbushell for Smashing Magazine, 2012.

0
Your rating: None