I tried to draw image stroke (border) to my png image.
(*expected 19px stroke layer style result by Photoshop)
and I found helpful script from imagemagick forum. (imagemagick discourse)
convert source.png -background '#2a7940' -alpha background -channel A -blur 9x11 stroked.png
but my best trial is far from Photoshop result.
I tried many combinations of Radius*Sigma but it seems the best result from blur trick.. (-blur 9×11 for this one)
Question
* Can I have better image stroke from Imagemagick or PIL or other CLI tools?
* If so, how..?
Thank you so much for reading this question.
3
Answers
This might get you started:
The
-transparent black
at the end is not optimal if your central image contains black so I will think about that some more…If you add
-write stroke.png
after the worddisk:19
you will get a new file calledstroke.png
that shows you what the morphology is doing.When you need clean edges on an effect you create with ImageMagick, you can double the size of your input image, run the operations, then resize it back to its original input size. It takes longer to run the operations, but the result can be substantially improved. Here’s an example command…
That command starts by reading the input image and storing a copy in a memory register named "mpr:in".
Then it resizes the input to 200% and uses "-morphology" to dilate the shape by about 38 pixels. That will work out to about 19 pixels after the image is reduced back to its input size.
Next it colorizes that new shape to make it green and resizes it 50%, which is back to the original size.
The command finishes by bringing back that "mpr:in" copy of the original image and compositing it over the modified green piece.
Increasing the size, working on that, and decreasing it after modifying it is called "super sampling". It’s a common technique that results in smoother edges, but it comes at the cost of speed.
Edited to add the output image…
Here is another way where I use -blur to anti-alias the stroke in ImageMagick.
Input:
If you need more antialiasing, increase the blur to 0x2.
For ImageMagick 7, replace convert with magick.