Rubber Stamp Effect

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?".
atariZen
Posts: 25
Joined: 2016-02-09T12:58:42-07:00
Authentication code: 1151

Re: Rubber Stamp Effect

Post by atariZen »

snibgo wrote: Personally, I usually put settings immediately before the operations they affect.

Commands should always be written in logical, chronological order. Do this, then do that, then do something else. Put settings before the operators they should affect, and so on.
That's very intuitive and sensible. Although when I tried to move the "+noise random" to the end of the grouping of options that affect it, it totally changed the result.

I like how fmw42 consolidated all the OPs code into one command, so I've been trying to maintain that style. But once multiple rubber stamps are needed, the code repetition is terrible. So I refined it to this bash code (which invokes convert 3 times):

Code: Select all

stamp()
{
    local lbl=$1
    local sz_opt=${2:+-size "$2"}

    convert \( $sz_opt -pointsize 128 -gravity center \
               -font Arial -background white \
               -fill red label:"$lbl" -fill none \) \
            \( $sz_opt xc: +noise random -channel g -separate +channel \
               -blur 0x2 -threshold 55% -transparent black \) \
            -compose over -composite -fuzz 10% -transparent white miff:-
}
convert <(stamp Top 500x200) rose: <(stamp Bottom 500x200) \
        -background transparent -append -rotate 90 -gravity east wizard: +swap -composite show:
I'm glad to find that ImageMagick works with bash FIFOs. That makes it easy to force scoping on all settings without creating temp files or trying to juggle multiple pipelines.

Notice that the rose is no longer centered:
Image (direct link)
The append operation lost the side-effect of the "-gravity center" that was inside the stamp grouping, thus changed behavior when the stamp imaging became externally sourced. This is expected, since -gravity is an image setting. So if I add an extra "-gravity center" before "-append", I get:
Image (direct link)
Post Reply