inner Border of an polyline

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
OE-MS1
Posts: 5
Joined: 2014-07-09T08:26:12-07:00
Authentication code: 6789

inner Border of an polyline

Post by OE-MS1 »

Hi eveybody,

I am trying to create a polygon, where i can change the thickness of the border inside the polygon.
The problem is by changing the strokewidth my actual polygon becomes larger, because the stroke becomes larger on both sides of its centerline.

-fill white -stroke blue -strokewidth 10 -draw "polyline 50,50 150,150 150,100 130,50 50,50" this does not work.

I would be plaesed if anyone could give me hint to solve my problem.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: inner Border of an polyline

Post by fmw42 »

This topic was moved from Consulting to Users forum, since Consulting is for Paid consulting.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: inner Border of an polyline

Post by fmw42 »

Here is a comparison of no strokewidth to one that is filled inward. You can adapt to your exact command line since you did not provide it. I use -morphology edgin to create a new thick line inside the polygon and composite it with the original simple line. See http://www.imagemagick.org/Usage/morphology/#edgein

Code: Select all

convert -size 250x250 xc:gray -fill white -stroke red +antialias -draw "polyline 50,50 150,150 150,100 130,50 50,50" tmp1.png
Image

Code: Select all

convert -size 250x250 xc:gray -fill white -stroke red +antialias -draw "polyline 50,50 150,150 150,100 130,50 50,50" \
\( -clone 0 -fill black +opaque white -morphology edgein octagon:8 \) \
\( -clone 0 -fill red -colorize 100 \) \
+swap -compose over -composite tmp2.png
Image
OE-MS1
Posts: 5
Joined: 2014-07-09T08:26:12-07:00
Authentication code: 6789

Re: inner Border of an polyline

Post by OE-MS1 »

Thank you very much. Your solution looks good. I am going to check it out.
OE-MS1
Posts: 5
Joined: 2014-07-09T08:26:12-07:00
Authentication code: 6789

Re: inner Border of an polyline

Post by OE-MS1 »

@fmw42

Hi your answer seems to work well. I am doing my coding on a PHP server and my admin only provides IM Version 6.2.8.
Is there a workaround without using -morphology and predefinded kernels?

Thank you
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: inner Border of an polyline

Post by snibgo »

Windows BAT syntax:

Code: Select all

convert ^
  -size 200x200 xc:gray ^
  ( xc:gray ^
    -fill white -stroke blue -strokewidth 10 ^
    -draw "polyline 50,50 150,150 150,100 130,50 50,50" ) ^
  ( xc:Black ^
    -fill White -stroke None -strokewidth 10 ^
    -draw "polyline 50,50 150,150 150,100 130,50 50,50" ) ^
  -composite ^
  p2.png
(Untested on such a pre-historic version of IM.)
snibgo's IM pages: im.snibgo.com
OE-MS1
Posts: 5
Joined: 2014-07-09T08:26:12-07:00
Authentication code: 6789

Re: inner Border of an polyline

Post by OE-MS1 »

you are right.
I will forward your comment to my admin.

your script doesn't do what i ment. But it gave's me a good hint do solve my problem by subtraction or something like this.

Thanks a lot

Matthias
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: inner Border of an polyline

Post by snibgo »

My second "-strokewidth" should be 1, not 10, though this makes no difference to the result.

My command composes with 3 images, so the third is a mask. It is black where pixels should come from the first image (the gray rectangle) and white where pixels should come from the second image (polygon with thick blue strokes). Because the third polygon isn't stroked, we hide the thickening that is outside the polygon.

The ChangeLog only goes back to v6.3.1-6, released in January 2007.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: inner Border of an polyline

Post by fmw42 »

IM 6.2.8 is ancient (over 600 versions old). -morphology edgin is much more current (6.5.9.3) and there was nothing like that command at 6.2.8. Best to use snibgo's solution
OE-MS1
Posts: 5
Joined: 2014-07-09T08:26:12-07:00
Authentication code: 6789

Re: inner Border of an polyline

Post by OE-MS1 »

thx
Post Reply