Dallas College, Richland Campus Multimedia Learning Center

Web Design 1

Inkscape


References


Introduction

The Inkscape Scalable Vector Graphics (SVG) image editor is an open-source project which provides us with a professional-grade, full-featured image editor, FREE.

This class will introduce you to some of the basic features of Inkscape. Keep in mind that Inkscape has a lot more to offer than what we will cover here.

Scalable Vector Graphics (SVG) images are a great choice in the Responsive Web Design (RWD) world. SVG images look sharp and clear on any display device, from large monitors to small phones.

But keep in mind that some images are NOT suitable for the SVG format. In particular, photographs of real-world objects will be best in the JPG format, not SVG.

Images that are suitable for the SVG format have sharp edges, lettering, geometric shapes (which can, though, be very complicated), sharp curves, etc.

Please NOTE: Some Web servers and/or browsers may limit your ability to view SVG images. In particular, Chrome has had major issues with blocking SVG images. The examples in this eHandout will work in Chrome, but this is mainly because I am using an <object> tag to display the SVG images in this handout. We will talk about the <object> tag later in this class.

Also please NOTE: Many mobile browsers may limit your ability to view SVG images. It appears that none of Firefox, Chrome, and Safari mobile browsers will display SVG images, at least as of the Spring of 2020.

Here is an example of an SVG image in a RWD page. Please note that there is nothing special about this image; it is a very simple, standard SVG image.

Now here is a similar image in PNG format in a RWD page. Move the right border of the window in and out to see how grainy the image looks at large sizes, especially on the curves and the lettering.


Installation

The first thing to do, of course, is to install Inkscape on your computer. Even the computers in the Lab and the classrooms here do not normally have Inkscape installed on them. No problem.

The installation programs are available for Windows computers, Mac computers, and UNIX-based computers. The main installation download page is here: https://inkscape.org

Click the "DOWNLOAD" menu item at the top of the home page, and then click the "Current Version" sub-menu.

Now click the "All Platforms" button at the right.

Click on the "Download" link for your computer.

The download should now start.

Execute/run the downloaded file to install the Inkscape app.

The first time you run Inkscape, it will take a few moments to find its tools and filters. Be patient as it starts up.


Editing Techniques

Now let's do some basic image editing. We will create our own image, but these techniques will be useful for editing an existing image, too.


Making a Custom Fill Object (Pattern)

If you need a "fill" pattern other than a solid color, you can make a Pattern object.


Considerations

SVG images are stored in plain text files, as XML code. You can view the text by opening the image in a standard text editor.

You can even change the image in the text editor, but you need to be really careful. It is quite easy to introduce mistakes and to make the image unusable.

If you would like to see what the XML code looks like, do this:

  1. Close Inkscape.
  2. Find the image that you have been working on, in Windows Explorer.
  3. Right-click the image name and pick "Edit with Notepad++", or "Open with" some other TEXT editor.

SVG in Chrome and Mobile Browsers

SVG images (as recently as Spring 2020) can sometimes refuse to display in the mobile Chrome browser, and in most mobile browsers.

I have done a lot of research into this problem and I think I have found a solution.

The Object Tag

In reality, there appear to be two possible solutions. I will present both of them here, and you can choose the solution that works in your site. Please note that the crucial part of both solutions is to use an <object> tag instead of an <img> tag for the SVG image.

Also, please note that the title attribute appears NOT to generate a tooltip for the object tag. You can add a very thick border to the object tag, and the border will display the title attribute's text, but this is not a recommended solution.

First Solution

The first solution is the simpler of the two, so I will present it first:

  1. Use an <object> tag, not an <img> tag. Apparently the main advantage of using an <object> tag is that you can tell the browser what kind of file it is preparing to display, whereas, with an <img> tag you cannot give the browser this information. The type attribute in the <object> tag gives the browser this information.

    Here is an example of an appropriate <object> tag:
    <object id="SVG_Object" type="image/svg+xml" data="images/ATUTuningImpedance.svg"></object>
    Please NOTE that the type attribute in the <object> tag is very specific and must be exactly like it is shown above. In particular, make sure you have "image/svg+xml" and NOT "images/svg+xml". In other words, this is NOT the name of your images folder!

  2. If you are using the w3.css stylesheet for RWD in your site, you may put classes such as w3-container and w3-third (etc.) into the <object> tag.

  3. Open the SVG image file in your favorite text/HTML editor.

    Change the width and height attributes in the <svg> tag to "100%" for each attribute.

    If you want to control the width more specifically, you may wrap the <object> tag in a <div> tag, to which you apply any relevant CSS properties, e.g., width: 100%. You may also apply a CSS width to the <object> tag, e.g., width: 60%.

Second Solution

The second solution is a bit more complicated, and appears to be unnecessary in most sites. But here it is, just in case the first solution isn't working for your site:

  1. Use an <object> tag, not an <img> tag. Apparently the main advantage of using an <object> tag is that you can tell the browser what kind of file it is preparing to display, whereas, with an <img> tag you cannot give the browser this information. The type attribute in the <object> tag gives the browser this information.

    Here is an example of an appropriate <object> tag:
    <object id="SVG_Object" type="image/svg+xml" data="images/ATUTuningImpedance.svg"></object>

  2. Put the <object> tag into a container such as a <div> tag which has an id attribute in it.

  3. If you are using the w3.css stylesheet for RWD in your site, you may put classes such as w3-container and w3-third (etc.) into the <div> tag.

  4. Open the SVG image file in your favorite text/HTML editor.

    1. WRITE DOWN THE CURRENT width AND height ATTRIBUTE VALUES THAT ARE IN THE <svg> TAG. You will need them to calculate "NN%", below.
    2. Change the width and height attributes in the <svg> tag to "100%" for each attribute.

  5. In your CSS stylesheet, make these adjustments and/or additions:

    1. The id selector for the <div> tag which contains the <object> tag needs to include at least these properties:
      • height: 0;
      • position: relative;
      • padding-bottom: NN%; (NN is the aspect ratio of the SVG image. You can calculate this percentage by dividing the image's ORIGINAL width by the image's ORIGINAL height, and multiply by 100.)
      • width: MM%; (MM is an appropriate width for the <div> in the page, e.g.: 90%)

    2. The id selector for the <object> tag needs to include at least these properties:
      • width: 100%;
      • height: 100%;
      • position: absolute;
      • left: 0;
      • top: 0;

Now I want to give credit to the person who wrote the article that I found which gave me this approach to displaying SVG images. Here is the main article: