Page 2 of 2
Re: How to erase everything inside a border?
Posted: 2014-07-29T09:27:03-07:00
by ooker
If I want to customize the width of the output border in pixel, what should I do? I can change the argument in the octagon kernel, but I would like to control exactly how wide it is.
Because this is the border, I would like when it is enlarges, it is aligned it in the middle, not in left or right.
Also, sometimes I would like the output to be a dotted line or a stroked line. Is there any way to manipulate this?
Thank you so much.
Re: How to erase everything inside a border?
Posted: 2014-07-29T10:21:20-07:00
by fmw42
Sorry this is not very clear to me. Can you show examples of what you want to happen and explain what you are trying to do for each example with an example output. You have too many cases. Break this into parts for each case with examples.
Re: How to erase everything inside a border?
Posted: 2014-07-29T11:05:17-07:00
by ooker
Re: How to erase everything inside a border?
Posted: 2014-07-29T11:26:56-07:00
by fmw42
The point is, when you enlarge the border, it expand inside. I would like it to expand equally inside and outside, which means the heart of the border is unmoved.
Yes, there is. Replace edgein with edge and half the octagon:size
Sometimes I would like the output to be a dotted line or a dashed line. Is there a way to change the code to achieve that?
Yes there is. See -draw about types of line strokes at
http://www.imagemagick.org/Usage/draw/#mvg_settings
I will have to get back to you later with updates on the script. I will be out most of the day.
Re: How to erase everything inside a border?
Posted: 2014-09-02T10:41:10-07:00
by ooker
I have tried to do that myself, and haven't succeeded. I ask you in a seperate thread
viewtopic.php?f=1&t=26191&p=114987#p114987 and you say there is no way. So can you help me again? Thank you.
Re: How to erase everything inside a border?
Posted: 2014-09-02T15:02:19-07:00
by fmw42
fmw42 wrote:Sometimes I would like the output to be a dotted line or a dashed line. Is there a way to change the code to achieve that?
Yes there is. See -draw about types of line strokes at
http://www.imagemagick.org/Usage/draw/#mvg_settings
I will have to get back to you later with updates on the script. I will be out most of the day.
Sorry I misunderstood your question. If you have a raster image with lines, I do not think you can easily change solid lines to dashed lines. You can only do that if you have a vector image such as SVG. The only way I can think to do that is to use the image as a mask and composite it with some other image that has a tiny checkerboard pattern.
Here is an example:
Code: Select all
convert -respect-parenthesis 1.png \
\( -size 3x3 xc:white xc:black +append \( +clone -flop \) -append \
-write mpr:checks +delete -size 640x480 tile:mpr:checks \) \
\( -clone 0 -alpha extract \) \
\( -clone 1 -clone 2 -compose multiply -composite \) \
-delete 1,2 -alpha off -compose over -compose copy_opacity -composite 1_proc.png
Re: How to erase everything inside a border?
Posted: 2014-09-02T15:05:00-07:00
by fmw42
fmw42 wrote:The point is, when you enlarge the border, it expand inside. I would like it to expand equally inside and outside, which means the heart of the border is unmoved.
This works for me by changing edgein to edge and making -bordercolor none and -border = octagon value or larger if needed and then shave by octagon value. So here I use octagon:2 which will add about 2 pixels to each side of the edge.
Code: Select all
infile="1.png"
color="black"
w2=`convert $infile -format "%[fx:w-2]" info:`
h2=`convert $infile -format "%[fx:h-2]" info:`
convert $infile -background white -flatten -fill black +opaque white -bordercolor none -border 2 \
-fill none -draw "matte 2,2 floodfill matte $w2,2 floodfill matte $w2,$h2 floodfill matte 2,$h2 floodfill" \
-fill white +opaque none -fill black -opaque none \
-alpha off -morphology edge octagon:2 \
-channel rgba -fill none +opaque white -fill $color -opaque white -shave 2x2 result.png
Re: How to erase everything inside a border?
Posted: 2014-09-03T11:42:15-07:00
by ooker
This one is cleaner. Thank you so much
Can I adjust the width of the line in pixel?
Re: How to erase everything inside a border?
Posted: 2014-09-03T12:53:16-07:00
by fmw42
ooker wrote:
Can I adjust the width of the line in pixel?
change the octagon value. It will put approximately one pixel on each side of the line. Or use a different shape, such as square. See
http://www.imagemagick.org/Usage/morphology/#kernel
Re: How to erase everything inside a border?
Posted: 2014-09-03T14:51:10-07:00
by ooker
Thanks.
When I try your code, it runs well. However when I try to make an output as a variable:
Code: Select all
infile="overlay.png"
outfile="overlay_cleaned.png"
width=3
w2=`convert $infile -format "%[fx:w-2]" info:`
h2=`convert $infile -format "%[fx:h-2]" info:`
convert $infile -background white -flatten -fill black +opaque white -bordercolor none -border 2 \
-fill none -draw "matte 2,2 floodfill matte $w2,2 floodfill matte $w2,$h2 floodfill matte 2,$h2 floodfill" \
-fill white +opaque none -fill black -opaque none \
-alpha off -morphology edge octagon:$width \
-channel rgba -fill none +opaque white -fill $color -opaque white -shave 2x2 $outfile
It gives this error:
Code: Select all
convert.im6: unable to open image `-opaque': No such file or directory @ error/blob.c/OpenBlob/2638.
convert.im6: no decode delegate for this image format `-opaque' @ error/constitute.c/ReadImage/544.
convert.im6: unable to open image `white': No such file or directory @ error/blob.c/OpenBlob/2638.
convert.im6: no decode delegate for this image format `white' @ error/constitute.c/ReadImage/544.
I don't know why it's wrong.
Re: How to erase everything inside a border?
Posted: 2014-09-03T15:03:32-07:00
by snibgo
What is the value of $color? That's the message you'll get if you haven't set it.
Re: How to erase everything inside a border?
Posted: 2014-09-04T02:06:22-07:00
by ooker
Stupid me. Thank you so much
