How to draw an arbitrary border line on image?

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
gurupk
Posts: 5
Joined: 2012-05-18T08:47:10-07:00
Authentication code: 13

How to draw an arbitrary border line on image?

Post by gurupk »

Hi,

I want to draw a rectangular line with some angle on the bottom part. Please see attached image.

This line need to be in different colors that user will select. What is the best way of drawing this type of border on an image.

Thanks,
Irfan
Attachments
Need to draw the border on the fly
Need to draw the border on the fly
curved.jpg (29.05 KiB) Viewed 24557 times
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: How to draw an arbitrary border line on image?

Post by Bonzo »

You have posted in the Imagick section - are you using Imagick with php?

Just checking as some people get confused between Imagick and Imagemagick.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to draw an arbitrary border line on image?

Post by fmw42 »

How did you create this the first time? If you have the same image and just need to change the color of the line, see -fill somecolor -opaque black. That will work if the line is not anti-aliased.

If you need to draw the line from scratch, then see -draw. There is no freehand part, but you can use curved shapes (ellipse) or bezier curves or polylines.

http://www.imagemagick.org/Usage/draw/
gurupk
Posts: 5
Joined: 2012-05-18T08:47:10-07:00
Authentication code: 13

Re: How to draw an arbitrary border line on image?

Post by gurupk »

yes I am using the php Imagick library.

Bonzo wrote:You have posted in the Imagick section - are you using Imagick with php?

Just checking as some people get confused between Imagick and Imagemagick.
gurupk
Posts: 5
Joined: 2012-05-18T08:47:10-07:00
Authentication code: 13

Re: How to draw an arbitrary border line on image?

Post by gurupk »

fmw42 wrote:How did you create this the first time? If you have the same image and just need to change the color of the line, see -fill somecolor -opaque black. That will work if the line is not anti-aliased.

If you need to draw the line from scratch, then see -draw. There is no freehand part, but you can use curved shapes (ellipse) or bezier curves or polylines.

http://www.imagemagick.org/Usage/draw/
I have created this image in the MS Paint. :)

What I want to achieve is to draw that line inside that curvy image, with different colors that is selected by users. Should bezier curves will do that?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to draw an arbitrary border line on image?

Post by fmw42 »

gurupk wrote:
fmw42 wrote:How did you create this the first time? If you have the same image and just need to change the color of the line, see -fill somecolor -opaque black. That will work if the line is not anti-aliased.

If you need to draw the line from scratch, then see -draw. There is no freehand part, but you can use curved shapes (ellipse) or bezier curves or polylines.

http://www.imagemagick.org/Usage/draw/
I have created this image in the MS Paint. :)

What I want to achieve is to draw that line inside that curvy image, with different colors that is selected by users. Should bezier curves will do that?

I do not know for sure. The best is to try different curves or polylines/polygon with -draw. see http://www.imagemagick.org/Usage/draw/

The problem is that IM is not interactive, so you have to specify each line segment or a curve.

If you can draw this shape elsewhere, then you can use that in IM and fill it with different colors. If you draw it without anti-aliasing, then you can also change the line's color once you get it into IM.
gurupk
Posts: 5
Joined: 2012-05-18T08:47:10-07:00
Authentication code: 13

Re: How to draw an arbitrary border line on image?

Post by gurupk »

Hi,

How can I draw an inner border?

I think this way i can achieve the solution. So if I have a PNG file and it has the curved from the bottom, so when i apply border inside, the library automatically draws the lines with the curve, not outer side, but inside the image with 3px inner.

Is this possible to do?

Thanks,
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to draw an arbitrary border line on image?

Post by fmw42 »

gurupk wrote:Hi,

How can I draw an inner border?

I think this way i can achieve the solution. So if I have a PNG file and it has the curved from the bottom, so when i apply border inside, the library automatically draws the lines with the curve, not outer side, but inside the image with 3px inner.

Is this possible to do?

Thanks,
Post an example image where you want the line drawn inside the border. And explain exactly where you want the line drawn.

Or see -morphology EdgeIn http://www.imagemagick.org/Usage/morphology/#edgein
gurupk
Posts: 5
Joined: 2012-05-18T08:47:10-07:00
Authentication code: 13

Re: How to draw an arbitrary border line on image?

Post by gurupk »

Hi,

Attach is the image, which I used to place a inside border, but it is not exactly rounded with the outer edge. This is done through series of image composition on each other.

But if there is a direct way to draw the border like this inside the image, then that will be great.

Please any thoughts.

Regards,
Attachments
bsave7.png
bsave7.png (3.3 KiB) Viewed 24360 times
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to draw an arbitrary border line on image?

Post by fmw42 »

OK. I took your image and got rid of the line. So my starting image looks like the following:

Image

Then I extracted the alpha channel, reduces its size by 10 pixels in each direction, got the edge from it, extended the edge image back to original size padding with black. Then I composited the image with a solid green image using the processed edge image as a mask.


infile="bsave7_new.png"
inset=10
color="springgreen3"
inname=`convert $infile -format "%t" info:`
ww=`convert $infile -format "%w" info:`
hh=`convert $infile -format "%h" info:`
ww2=`convert xc: -format "%[fx:$ww-$inset]" info:`
hh2=`convert xc: -format "%[fx:$hh-$inset]" info:`
echo "$infile; $inset; $color; $ww; $hh; $ww2; $hh2;"
convert $infile \
\( -size ${ww}x${hh} xc:"$color" \) \
\( -clone 0 -alpha extract -resize ${ww2}x${hh2}! -edge 1 -background black -gravity center -extent ${ww}x${hh} \) \
-gravity center -compose over -composite ${inname}_line.png

Image
Post Reply