March 8th, 2008

One of the advantages of SVG over some other graphics capability is the fact that SVG is vector-based. A vector graphic means that images are created via *recorded mathematical primitives (circle, line, square, etc.) rather than based on fixed pixels. Because SVG is a vector graphic, the same image can be sized very small or very large and remain crisp and bright regardless of the size. Typically the image has a smaller file size, too.

This doesn't seem like a big deal if the image is placed in a weblog post, and statically sized. My own use of SVG at this site is statically sized and I could just as easily use JPEGs or PNGs, other than the fact that I recreate the images based on the header graphic. However, over at the main Burningbird site, I'm experimenting around with using SVG as a resizable background element, and it's this use that truly demonstrates why SVG can be such an advantage over bitmap images.

Consider computer monitors and the problems we've always had about differing monitor sizes. Either our content seems to extend beyond the edges of the browser, generating a horizontal scroll bar. Or it's a skinny little bar in the midst of a vast expanse of blank space. Even if we use a background image and repeat it, we still end up with a mind numbing expanse of *nothing*.

As an alternative to the static, repeating background image, I used an SVG image I found at the Open Clip Art site, sized dynamically in the background, and statically in both the header and footer. For the background image, attributes on the SVG element provide further instructions in how the image is resized, and whether to maintain perspective or to have the image fill the given space. Right now, I have turned off the perspective, and the result is interesting when viewed in different sized windows.

biggershot
Uploaded with plasq's Skitch!
Burningbird » Time Lapse Photography
Uploaded with plasq's Skitch!
Burningbird
Uploaded with plasq's Skitch!
Burningbird » History
Uploaded with plasq's Skitch!

Providing a dynamically sized background image is a fairly new use for SVG, so it's not without challenges. Opera on the Mac has problems with the resizing, as well as the gradients used in the image; Safari has problems with the gradient, though Webkit works nicely. However, I originally tried this approach using an external SVG file, incorporated into the page using the object element, but WebKit had problems with the object element. At this time, Firefox 3b3 is the only browser that manages both the gradient and the sizing, in addition to SVG inline or linked externally. I expect, though, that all three–Safari, Opera, and Firefox–will do well with using SVG for a background image in their next released versions.

As for IE, the entire site shows up primarily in black and white. The site is so plain, in fact, that I have a link labeled, "Why is this page so plain", to a page explaining my use of SVG that only shows up when the site is accessed by IE. As I'll be incorporating SVG into all of my sites, I'll be continuing my "B&W" support for IE to all the sites, rather than restrict access with the XHTML MIME type, as I originally did with this site.

ieshot
Uploaded with plasq's Skitch!

Apple announced that it will be supporting SVG in the version 2.0 of the iPhone SDK because, according to a story on the topic, SVG is a resolution-independent image format that is highly compressible. The three variations of the same image at Burningbird demonstrate the resolution independence, with the image looking good in the site footer, the larger header image, and the potentially very large background.

Once I've debugged why the image isn't loading using the object element in Safari/Webkit, I could use one external gzipped SVG file, and eliminate most of the size constraints. The only restriction with using an external SVG file is that using the object element for the background can cause some odd behavior with IE. In addition, from a drawing performance perspective, I also found the inline SVG to be the best of the two options.

Eventually, though not implemented in any browser that I've been able to see, we'll be able to set the SVG background using the CSS background-image attribute. This just adds to the intriguing possibilities. update This functionality is implemented with Opera 9.5, as demonstrated in this example.

*Bonus material: a detailed instruction video from Nortel on the differences between raster and vector graphics. This is an older video, though. Support for SVG has increased, both with editing tools and with browsers. Other video formats and image lessons from the Nortel LearniT page.

Update I'm just playing around with this pattern, I'm aware that not all browsers are processing it correctly. This gave me a chance to do a little browser testing and also have a little fun with color. We've had so much cold and snow that I was desperate for a little color.

Comments
1
Bud Gibson - 10:17 pm March 8, 2008

I like the black and white to IE idea. That will likely motivate people more in that they will see that the site is working, but they will also know they are not getting the full effect. Consider putting a few "this is what you could be seeing" screenshots a la this post.

I'll point out that you have gotten me using experimental browsers. I'm on the verge of downloading an opera beta just to see some of these things.

I like the scalable background image. Quite creative.

2
Jeff Schiller - 11:36 pm March 8, 2008

Shelley,

"Black & White" = brilliant

As far as I was aware, Opera 9.5 supports CSS background-image pointing to a SVG image.

Regards,
Jeff

3
Peter Gasston - 4:30 am March 9, 2008

Opera 9.5 will support SVG in background images, and Safari supports multiple background images, but no browser supports multiple SVG backgrounds yet.

4
Shelley - 8:08 am March 9, 2008

The B&W ended up being the most effective approach. And now I can have my fun!

I tried out Opera's 9.5b, but if it supports SVG for the background-image, it doesn't yet have this implemented. Either that, or it doesn't like the SVG I've tried. I'm going to be very curious as to how this will work when it does.

I need to find another image to test that doesn't have the gradient challenges this one did. I found one with two cardinals that's quite pretty. I have to first finish the site changes first, though, incorporating Drupal and finding a better XHTML validation library (the one I sent you Jeff isn't working well with attributes).

I also need to update this site to the new B&W.

5
Peter Gasston - 8:27 am March 9, 2008

Here's an example of using SVG in the background image.

Obviously you will need Opera 9.5 beta to see it!

6
Shelley - 8:45 am March 9, 2008

Thanks Peter. I tried one of my other SVG files and was also able to get it to work with Opera 9.5. Must play more.

7
Jeff Schiller - 10:17 am March 9, 2008

I've experimented with it before too in Opera 9.5 and found it a little buggy (sometimes appearing as the background properly and not other times). I kind of gave up on it for the moment…

8
Rijk - 11:41 am March 9, 2008

I just added an SVG gradient as background image for the page and the header box on my Customize Opera page a few days ago. As I don't know anything about SVG, so it was a bit of a challenge to figure out that the weird rendering I saw was a bug in Opera. I worked around it for now, but apparently having a border on a box makes the background image scaling for that box go off in a weird way.

For this site I use 'system colors' only, and I was happy to see they even worked in the SVG. Disadvantage is that the site doesn't come close to being pretty :)

9
Michael R. Bernstein - 11:41 am March 9, 2008

Shelley, I *like* this 'B&W for IE' approach. A lot.

However, I took a look in Firefox 2, and this breaks rather horribly (mostly-black flowers, off-center and scaled wrong, header and footer layout broken). I can email a screenshot, if you like.

Also, a copy edit on the 'black and white' page: It is 'Scalable Vector Graphics', not 'Scalar'.

10
ws79 - 12:35 pm March 9, 2008

Shelly,
there is an error in inline svg what you used. The error is invalid value for property FILL. Example: fill: url(#xlinearGradient6019) rgb(0, 0, 0); just remove rgb(0, 0, 0).

11
Shelley - 2:14 pm March 9, 2008

That's not a bug ws79. When a URI is used to specify a fill gradient, pattern or custom paint, you can also specify a color using the rgb function (or named color) following, in case that gradient et al is missing or invalid. Webkit and Firefox 3b3 handled it correctly, but Safari, Firefox 2, and Opera 9.5b did not.

I hesitated to fix it, and will only fix it for the background flower and top, because I've filed a bug report with Opera.

I'm just playing around with this pattern — I don't plan on using it permanently. I'll most likely create my own SVG, or an image based on modifying existing SVG, so that's it more my effort. Plus I'll use SVG that won't trigger any errors in most of the browsers.

This is just playing around with a little color.

12
Shelley - 2:15 pm March 9, 2008

Thanks for the correction, Michael. I always get that wrong.

13
Shelley - 2:20 pm March 9, 2008

Rijk, that's cool.

14
Oliver - 4:41 pm March 9, 2008

If you felt generous you could file any bugs you saw in WebKit at http://bugs.webkit.org :D

15
Drew LeSueur - 6:11 am March 10, 2008

Cool site. The SVG background on http://www.burningbird.net isn't rendering correctly on my Firefox v 2.0.0.12 on my computer using Windows Vista. I checked to see that I have the latest version of Firefox.

16
stelt - 4:20 am March 20, 2008

If you have SVG giving errors on some browsers, maybe you should check the content at http://validator.w3.org

Luckily Safari 3.1 is out, Firefox 3 and Opera 9.5 are near,
and IE marketshare keep slowly sinking, meaning an overall big jump in SVG support of the average websurfer.

17
Shelley - 8:12 am March 20, 2008

Stelt, the validator only validates based on the DOCTYPE, which means other namespace elements will generate errors, though they are not errors.

Thanks to all those who have contributed to the discussion. Comments are now closed, but you can contact the author of the post directly.