Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8632797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:24:03+00:00 2026-06-12T09:24:03+00:00

I have a long time project: a basic vector graphic tool which runs in

  • 0

I have a long time project: a basic vector graphic tool which runs in browser and uses SVG and Javascript (maybe you have seen somekind of these elsewhere). The tool has only very limited set of functions, because the audience is restricted and the purpose is very specific and in fact there are not allowed to be other functionality than what is explicitly allowed (you know). One missed feature is eroding (also known as inset or thin) and dilating (outset, thicken, bolden) polygons and other graphical elements.

I have used Adobe Illustrator’s Offset Path Effect many times and with it I can easily make copies of graphical objects that are thinned or thickened, without affecting the original object, which therefore can be nearly whatever supported by the program.

I have tried to get the same functionality to function in SVG, but without success.

I have tried the following:
– dilate and erode filters, but with not satisfying results (please see the image here)
– Server-side Python’s Shapely library, but this workaround is too slow and allows to inset or outset only the basic polygons (description here)
– to find javascript library / code / function, which could alter the path data of graphical elements, but found nothing for javascript

So is there any meaningful way to implement this like Offset Path Effect and how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:24:03+00:00Added an answer on June 12, 2026 at 9:24 am

    This is an "Answer your own question – share your knowledge, Q&A-style" -style answer, but if you have some better answer, please freely use your keyboard.

    I have used SO only a few days, so please don’t downvote me to the gap. I got an interesting workaround idea to this issue, which is based on variable-width strokes and masks.

    But let’s start at your (or my) first idea. When we are going to erode (thin) graphical objects in SVG, the obvious first thought is to use erode filter:

    But because erode filter (and dilate as well) uses pixel data (the rasterized path) the result is not good looking in all cases. In fact I have never seen a good-looking erode when used to filter vector objects. See the hat and mouth:

    Eroded image

    The dilate filter has similar problems (the nose is not nice and the baseball cap is scrappy and some other inconsistencies):

    Dilated image

    All users of Adobe Illustrator know the nice path effects, which can be used to apply various path operations to shapes (objects). These effects doesn’t change the original path data, they only create a modified copy of object. One of the most usable is Offset Path Effect, which can be used to set off from the selected object by a specified distance (or something similar). SVG:s erode and dilate filters have similarities with Illustrator’s Offset Path Effect, but the quality is as a vector operation (versus bitmap) high.

    SVG format in it’s current state, lacks support for Illustrator-like Offset Path, but it’s possible to get the same functionality using variable-width strokes and masks as noted here.

    Let’s dive into the world of SVG masks. The dilate (or outset path or thicken) is possible to achieve by simply increasing a stroke width, but erode (or inset path or thinning) needs something more, for example masks. In SVG, any graphics object or ‘g’ element can be used as an alpha mask for compositing the current object into the background (W3C SVG 1.1 Recommendation).

    The above means that not only object’s fill can be used as a mask, but also a stroke. And adjusting the width of the stroke of the path that is used as a mask, we can control how much of the current object (into which the mask is applied using mask attribute) is masked out.

    Let’s get an example of using mask. First we define a path in SVG:s defs element:

    <defs>
    <path id="head_path" d="M133.833,139.777c1 ...clip... 139.777z"/>
    </defs>
    

    When we define a path in defs element, it eliminates the need for repeating the same data in other parts of document. The path’s id attribute is used to refer to the path from some point(s) of the document.

    Now we can use this path data in mask:

    <defs>
    ...
    <mask id="myMask" maskUnits="userSpaceOnUse">
    <use xlink:href="#head_path" fill="#FFFFFF" stroke="#000000" 
    stroke-width="18" stroke-linecap="round" stroke-linejoin="round"/>
    </mask>
    ...
    </defs>
    

    The ‘use’ element references to the ‘path’ element, whose id is ‘head_path’ and indicates that the graphical content (in this case only the path data) of ‘head_path’ element is included at this mask. The stroke-width that is defined on the above ‘use’ element will be the amount of offset (erode) effect. This amount is masked out of the element in case, which we are going to draw next.

    Okay, let’s draw first the ‘head’ without masking to see how beautiful it is:

    ...
    </defs>
    <use x="5" y="5" xlink:href="#head_path" fill="#4477FF" stroke="black"
    stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
    

    This produces the following shape:

    Original shape

    Now test, what we can achieve using mask:

    ...
    </defs>
    <use x="5" y="5" xlink:href="#head_path" fill="#22EE22" stroke="black"
    stroke-width="21" stroke-linecap="round" stroke-linejoin="round"
    mask="url(#myMask)"/>
    

    The above ‘use’ element is instructed to use ‘myMask’ as a mask and ‘head_path’ as a graphical content. The mask effect is applied to the ‘use’ element and the following shape is drawn:

    Masked shape

    If we stack both on top of each, we can compare the original head to the masked head:

    Original and masked shape

    Not bad at all? Let’s compare the first attempt using SVG erode filtered version to the masked version:

    Eroded vs masked

    The left one is erode-filtered and the right one is masked to imitate Illustrator-like Offset Path Effect. No odd artifacts in the hat and mouth!

    How about dilate then? Is there a way to remove the path unfidelity on nose and scrappiness of the baseball cap? Sure. And the method is really simple but sort of hack. Fortunately there is no need to use masks. Instead we can adjust stroke-width to achieve the desired effect. And because the stroke is already used for boldening, to get a black stroke around boldened shape (if ever wanted), we have to add an additional copy of element with a little wider stroke and lay it out below the boldened shape:

    <!-- To get the black stroke -->
    <use x="220" y="5" xlink:href="#head_path" fill="red" stroke="black"
    stroke-width="24" stroke-linecap="round" stroke-linejoin="round"/>
    <!-- To get the boldened shape -->
    <use x="220" y="5" xlink:href="#head_path" fill="red" stroke="red"
    stroke-width="21" stroke-linecap="round" stroke-linejoin="round"/>
    

    This produces the following shape:

    Offset Path Effect applied

    Here both the original shape and the one with our custom Offset Path Effect applied:

    Original and Offset Path Effect applied

    How our custom boldening compares to dilate filter:

    Dilated vs Boldened

    The left one (above) is dilated using SVG:s dilate filter, the right one is boldened using our custom Offset Path Effect. Pretty nice, I like. Path follows faithfully the original path at the given distance and no signs of scrappiness on baseball cap.

    And finally let’s pull all the wires together:
    Dilate/Origina/Erode vs Offset Path Combined

    The left one (above) uses dilate/erode filter of SVG and the right one uses Illustrator-imitated Offset Path Effect, which is achieved using SVG mask and thicker strokes. Which one you would choose?

    Conclusion: We are not forced to use Javascript or other scripts to thicken or thin graphical elements in SVG. Erode and Dilate filters of SVG may have some using purposes, but they are not well suitable for high-quality path "modifications". Masks are a little complicated to use, but after few experiments you get familiar with them. I really hope that SVG in the future would support Offset Path Effect natively, without using this like hacks.

    I jsfiddled the shapes used in these examples for you to play with filters and masks: http://jsfiddle.net/7Y4am/
    (Test at least to change stroke widths!)

    (Sorry my bad English, which get native speakers to laugh until die, but please remember, I belong to the 94% of humanity, who does not speak English natively. But fortunately we have Google Translate.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a DLL project which has existed for a long time (maybe as
I have project which is currently working and was developed long time back on
I have a very large VC++-Project which takes a long time to Rebuild after
I have been using attachment_fu on a project for a long time and all
I have some projects for which I have ceased development a long time ago
I have a program which takes a long time to complete. I would like
I have worked in project for long time but after electricity has cut off
I have been working on a project for a long time now and there
I have an AI project, which uses a Backpropagation neural network. It is training
I have a long-time-to-build (setup) project in a Visual Studio 2010 Solution. It is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.