Stroking

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
sfg
Posts: 17
Joined: 2009-12-30T13:44:31-07:00
Authentication code: 8675309

Stroking

Post by sfg »

How can I stroke an image with a 1px border, like this image: http://img.photobucket.com/albums/v635/sfg/miss0042.png
I could splice it in all four directions with convert, but I want to do it for many files at once so to my understanding that's only possible with mogrify which gives me a "unrecognized option 'splice' " error.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Stroking

Post by fmw42 »

convert image -bordercolor black -border 1 result

will add a 1 pixel border outside the bounds of the image

see http://www.imagemagick.org/Usage/crop/ and esp http://www.imagemagick.org/Usage/crop/#border
sfg
Posts: 17
Joined: 2009-12-30T13:44:31-07:00
Authentication code: 8675309

Re: Stroking

Post by sfg »

Not working. It fills all the transparency with black. I tried -background none but that has no effect.
The files are transparent .png so I need to keep that transparency.
sfg
Posts: 17
Joined: 2009-12-30T13:44:31-07:00
Authentication code: 8675309

Re: Stroking

Post by sfg »

And isn't there a way to use splice with mogrify? Because that would solve this problem just fine.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Stroking

Post by fmw42 »

don't think splice works with mogrify. you can try. I am not sure. mogrify is old and does not support all functions that convert does.

try

convert image -channel rgba -alpha on -bordercolor black -border 1 result
sfg
Posts: 17
Joined: 2009-12-30T13:44:31-07:00
Authentication code: 8675309

Re: Stroking

Post by sfg »

Nope, still the same.

And if mogrify is old, is there any other way to convert a batch of images and replacing the old files like mogrify does?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Stroking

Post by fmw42 »

other than scripting a bunch of images or using wild cards, no other similar way to mogrify and I am not too sure about how to use wild cards to do a sequence of images.

try

convert miss0042.png -alpha off -bordercolor black -border 10 -alpha on miss0042_b10.png

for multiple images, you can try

convert image1.png image2.png .... alpha off -bordercolor black -border 10 -alpha on miss0042_b10_%d.png

or if all the files are in the same directory and no other files,

convert miss*.png -alpha off -bordercolor black -border 10 -alpha on miss_b10_%d.png
or
convert *.png -alpha off -bordercolor black -border 10 -alpha on miss_b10_%d.png


not too sure about the latter two

The other way is to write a script and loop over all you images.

see for example:

http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO-7.html
http://www.cyberciti.biz/faq/bash-for-loop/
http://www.cyberciti.biz/faq/bash-while-loop/
http://hacktux.com/bash/file
http://aplawrence.com/Basics/bash_looping.html
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Stroking

Post by fmw42 »

Just did a test and this seems to work with mogrify

I put 3 copies of your image into a directory test1 and created an empty directory test2. The following processes each image in test1 and puts the result with the border around it in directory test2

cd test1
mogrify -path /Users/fred/test2 -format png -alpha off -bordercolor black -border 10 -alpha on *.png
sfg
Posts: 17
Joined: 2009-12-30T13:44:31-07:00
Authentication code: 8675309

Re: Stroking

Post by sfg »

Aha! Perfect! Thank you very much!
Post Reply