Internet

Creating images with a text editor

February 25, 2009, 02:03 PM — 

No, I'm not talking about ASCII art like this little crab. I'm talking about scalable vector graphics or SVG files.

     /\
    ( /   @ @    ()
     \  __| |__  /
      -/   "   \-
     /-|       |-\
    / /-\     /-\ \
     / /-`---'-\ \
      /         \

Even if you're familiar with the basic difference between raster and vector images, it might not be immediately obvious that you can create simple images using nothing more than a text editor.

Here's a very simple example. The instructions below define a small red circle with a black border. These lines comprise an entire SVG file. Put the code in a text file, call it something like "eg1.svg" and drag it into a browser. Voila! You have a circle.

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg">
<circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/>
</svg>

Roughly half of the code in this example identifies the type of file content as SVG and establishes some style settings. The text following the "circle" tag defines what our circle will look like. The cx and cy settings define the x an y coordinates for the circle's center. The r setting defines the circle's radius. The stroke and stroke-width settings then determine the color and width of the circle. Lastly, the fill determines the color to be used inside the circle. Change this to "orange", "turquoise" or "lavender" and your circle changes color.

If you try the code in the next example and drag the file into a browser, you will see a very large circle, most of which has extended beyond the borders of your browser window. That leads to what I think of as the most beneficial aspect of vector graphics -- you can grow them to practically any size and still have good resolution. Where a raster file will quickly lose its clarity if stretched beyond its normal resolution, you can stretch a vector file to cover a billboard and it will still look good. Changing the radius setting in this example from 900 to 54000, for example, would be doing just that. It won't fit on your screen any more -- in fact, you'll literally just see red! -- but it will be a handsome circle just the same.

Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world

I like it!
Comments

Creating images with a text editor

"Put the code in a text file, call it something like "eg1.svg" and drag it into a browser. Voila! You have a circle." That sentence summarized the how-to I'd been searching for.
| reply

the path has changed

the path to the lion picture has changed. the new path is:

http://croczilla.com/bits_and_pieces/svg/samples/lion/lion.svg


and there are a lot more samples and info here:
http://croczilla.com/bits_and_pieces/svg/


Thanks for the article. I did not realize how straight forward the syntax was, pretty slick! guess I will have to play around with it a bit.

I've known about svg for a long time, but have not paid much attention to it due to the many browser compatibility issues. Your article would be a lot more helpful if you would add a list of browser versions that actually support it.

| reply
peer-to-peer

Esther Schindler
If the comments are ugly, the code is ugly

claird
SVG a graphics format for 21st century

pasmith
Take Chrome OS for a test spin

Sandra Henry-Stocker
Solaris Tip: Have Your Files Changed Since Installation?

sjvn
64-bits of protection?

jfruh
Android fragments vs. the iPhone monolith

mikelgan
What Gizmodo missed about the Pro WX Wireless USB disk drive

 

Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325

Join the conversation here

The Daily Tip

The Daily TipQuick, practical advice for IT pros. Made fresh daily.

Hot tips:

Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.

Newsletters

Subscribe to ITWORLD TODAY and receive the latest IT news and analysis.

I would like to receive offers via email from ITworld partners.
By clicking submit you agree to the terms and conditions outlined in ITworld's privacy policy.
Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

Marketplace