Apply opacity mask and annotate watermark with imagemagick - imagemagick

I'm finding a way to apply a watermark and opacity mask for an image using imagemagick.
Source
Result
Thank you all for reading.

Thanks emcconville for a nice solution but still it needs the rectangle of the image size. I've found a better solution that we don't need to specify rectangle of the image.
convert a.png -brightness-contrast -60x-50 -pointsize 120 -gravity center -draw "fill white text 0,0 'SOLD'" b.png
I hope this would be useful for someone.

This is pretty basic, and fun, stuff with ImageMagick. Examples and details in the article "Annotating". Opacity mask & watermarking may be overkill when simple annotation & drawing will work.
convert source.png \
-fill "#0009" -draw 'rectangle 0,0,450,335' \
-fill white -pointsize 64 -gravity Center -annotate 0 "SOLD" \
sold.png

Related

Change Background in Image (Imagemagick, GraphicsMagick, ...)

I have scanned books with black imitation leather as background.
The text recognition unfortunately recognizes text on this background. I like to color the border black, so that the program does not find any text at the edge. Is this possible with tools like ImageMagick or GraphicsMagick?
Here is an example (original is in tif):
Perhaps a combination of floodfill and fuzz?
convert input.png -fill white -fuzz 20% -draw 'color 1,1 floodfill' output.png
Also checkout Fred's awesome textcleaner script.
emcconville has an excellent solution. I might add just a bit to it to include some deskew and trim/shave, since your margins are large enough to permit shaving the excess black that remains after a trim. The deskew might help in the OCR.
convert image.png -bordercolor black -border 1 -background black -deskew 40% -fuzz 50% -trim +repage -shave 10x10 result.png

How to position the -draw in imagemagick?

I am using imagemagick to draw a border on the top of an image.
THIS IS MY CODE:
convert source.jpg -stroke red -strokewidth 2 -fill transparent -draw \"roundrectangle 10,10 628,151 10,10\" source.jpg
This works fine but i need to be able to position the -draw where i want.
I tried to position the border like using -geometry like so:
convert source.jpg -stroke red -strokewidth 2 -fill transparent -geometry +5+15 -draw \"roundrectangle 10,10 628,151 10,10\" source.jpg
But this does not position it where i want. I also tried using -gravity and that doesn't work either!
Could someone please advise on this?
Thanks in advance.
Bonzo is correct, you cannot use -geometry with -draw.
In ImageMagick with -draw you can also translate to where you want the center to be and then specify +- distances to the corners from the center placement.
Suppose you have a 100x100 size box you want draw and you want it centered at 250,250, then
convert input.jpg -stroke red -strokewidth 2 -fill transparent -draw "translate 250,250 roundrectangle -50,-50 50,50 10,10" output.png
That makes it easier to draw the same size boxes at different locations.
see
http://www.imagemagick.org/Usage/draw/
http://www.imagemagick.org/script/magick-vector-graphics.php

How to underlay circle with mogrify in one command

I wrote this script and it's working fine, but I would like to do all of it in one step on the fly, without the extra temp image.
explanation: i have a lot of broken image files and i want to draw a circle underneath each image. for this i have to create a temporary image circle.png and then use "image DstOver" to place it below each of the images:
convert -size 200x200 xc:transparent -fill red -draw 'translate 100,100 circle 0,0 100,0' circle.png
mogrify -draw "image DstOver 0,0 0,0 'circle.png'" images/*.png
Something along the lines of:
mogrify -fill red -draw "DstOver translate 100,100 circle 0,0 100,0" images/*.png
But this is always giving me an error, no matter where i place the DstOver:
mogrify: non-conforming drawing primitive definition `DstOver' # error/draw.c/DrawImage/3169.
Composition operators like "DstOver" are only used with the "image" primitive of "-draw". Just omit it. See the "-draw" entry in the ImageMagick commandline documentation.
You can have multiple "-draw " options, some drawing figures such as "circle ..." and others such as "image DstOver ...".
I am not sure what you are trying to do, but in general, mogrify will have trouble doing anything with multi-image operators or stack operators. The only exception I know of is the -draw image operator, so you need to create your image up-front and then use that:
# Blue rectangle with transparent centre
convert -size 200x200 xc:none -bordercolor blue -border 50 start.png
# Your circle
convert -size 200x200 xc:white -fill red -draw 'translate 100,100 circle 0,0 100,0' circle.png
# Now underlay
mogrify -draw "image DstOver 0,0 0,0 'circle.png'" start.png

How to create transparent image for rubber stamp in ImageMagick

I have to create an image, which is an overlay texture made up of a white image with some transparency to give it the appearance of a rubber stamp.
For reference see the image "stamp_overlay.png" in the video http://railscasts.com/episodes/374-image-manipulation .
This is what i did:
convert -size 70x70 canvas:white stamp_overlay1.png
and then
convert stamp_overlay1.png -transparent white stamp_overlay1.png
But how do I make it like the image?
I am pretty much new to ImageMagick. Any help is highly solicited.
Updated Answer
Ok, I got that wrong! You want to create a stamp overlay, not overlay a stamp overlay. You can do that like this:
# Create white square, draw a black rectangle, then make black pixels transparent
convert -size 300x300 xc:white \
-fill black -draw "rectangle 20,100 200,280" \
-transparent black out.png
Original Answer
I find your question very hard to understand, but I think I know what you want. First, let's create a solid red image
convert -size 70x70 xc:red red.png
then let's composite the stamp_overlay.png image on top
convert red.png stamp_overlay.png -composite out.png
which gives this
but now you want to make the white areas transparent, so you need to do this:
convert red.png stamp_overlay.png -composite -transparent white out.png
and that still looks the same on this white background, but it isn't :-)

Apply watermark with text / image using GraphicsMagick

I need to be able to apply watermark on an image, using either text or another image.
Getting it to work with an image was quite straight forward, using the following command:
gm composite -dissolve 15 -tile logo.png image.jpg wmark_tiled.jpg
Now, I also want to be able to use text for watermarking (in other cases). The only thing that I found close to it, is a command from ImageMagick tutorial which is the following :
convert -size 140x80 xc:none -fill grey -gravity NorthWest -draw "text 10,10 'copyrigh text'" -gravity SouthEast -draw "text 5,15 'copyright text'" miff:- | gm composite -tile - image.jpg copyrightImage.jpg
Although its not working in GM, and I would rather avoid using pipe as it causes some headaches managing it from Java.
What I thought I could do, is generate an image from a given text, and then use that image as logo.png is used on my first command. Although I cannot find how to generate an image out of text, all I find is putting text on top of an image.
Ideally I will generate a transparent image with the text, and from what I see modifying font/color etc should be quite flexible.
Any suggestions on how to achieve this, or any better solutions are welcome.
(I added imagemagick tag as the interfaces are often same/similar)
I'm not sure I fully understand your query, so apologies if I've misunderstood, but are you trying to create a transparent image, with some text in the corner? If so, would this not work?
convert -background transparent -fill grey -font Calibri -size 140x80 -pointsize 14 -gravity southeast label:'copyright text' output.png
Obviously adjusting the font, pointsize, output image name etc. That would create the following:
http://oi42.tinypic.com/14j1bvp.jpg
P.S. that was written for ImageMagick. I don't know how GM differs or whether it would still work.
To be able to get the watermark text into the same image I had to use the -annotate parameter.
So Moogle's code snippet would look like this in my case:
convert original_image.jpg -background transparent -fill grey -font Calibri -size 140x80 -pointsize 14 -gravity southeast -annotate +0+0 'copyright text' output.jpg

Resources