Watermarking with Text.

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
Watermarked
Posts: 5
Joined: 2017-12-05T20:08:50-07:00
Authentication code: 1152

Watermarking with Text.

Post by Watermarked »

I have run into a little issue, where I have had absolutely no luck in trying to implement some of the public examples on the ImageMagick website mainly due to not knowing how to format the command within PHP. I took a piece of open source code and tweaked it to fit my needs, the final part is actually configuring the ImageMagick command in order to achieve the desired effect which is;

Image

A repeating watermark slanted in the same direction. Please note that the current command I use is;

Code: Select all

// Build the imagemagick command - using rgba so the opacity of the text can be set
$cmd = "$original_image -pointsize 50 -font /var/www/html/static/fonts/arial.ttf -fill rgba\(0,0,0,0.4\) ".
" -gravity center -annotate +0+0 \"$text_submitted\" ";
$original_image is an unwatermarked image file submitted from a form,
$text_submitted is the text submitted from a form, which of course will output the following;

Image

I am currently using Debian 8 with PHP 5.6.30, here is some information on what version of Imagick I am using;

Image

I have really tried to get this working on my own but I just cannot and would really, really appreciate an experts help on the matter. Thanks in advance.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Watermarking with Text.

Post by snibgo »

What command do you actually run? What you have shown has no "convert" at the start, nor an output filename at the end.

What error message do you get?
snibgo's IM pages: im.snibgo.com
Watermarked
Posts: 5
Joined: 2017-12-05T20:08:50-07:00
Authentication code: 1152

Re: Watermarking with Text.

Post by Watermarked »

snibgo wrote: 2017-12-05T20:38:49-07:00 What command do you actually run?

Code: Select all

$cmd = "$original_image -pointsize 50 -font /var/www/html/static/fonts/arial.ttf -fill rgba\(0,0,0,0.4\) ".
" -gravity center -annotate +0+0 \"$text_submitted\" ";
$original_image is an unwatermarked image file submitted from a form.
$text_submitted is the text submitted from a form, which of course will output the following.



snibgo wrote: 2017-12-05T20:38:49-07:00 What you have shown has no "convert" at the start, nor an output filename at the end.
This portion saves the file I believe;

Code: Select all

exec("convert $cmd  $new_image 2>&1", $array);
snibgo wrote: 2017-12-05T20:38:49-07:00 What error message do you get?
I do not get any errors, as it currently stands this is what outputs;

Image

I am wanting to change the magick command to output a similar result to;

Image

Which as described, is a tile/repeating piece of text with left titled orientation.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Watermarking with Text.

Post by snibgo »

So, it successfully writes text, as we see on the circular image. Correct?

The colourful rectangular image seems to have no text.
snibgo's IM pages: im.snibgo.com
Watermarked
Posts: 5
Joined: 2017-12-05T20:08:50-07:00
Authentication code: 1152

Re: Watermarking with Text.

Post by Watermarked »

snibgo wrote: 2017-12-05T20:50:02-07:00 So, it successfully writes text, as we see on the circular image. Correct?

The colourful rectangular image seems to have no text.
Im sorry fella, I am explaining this retarded. Let me clear it up, so the command I have posted above in the quotes successfully produces this image;

Image

In the center you can see the text, I have tested this following line;
" -gravity center -annotate +0+0 \"$text_submitted\" ";
Changing it to
" -gravity North -annotate +0+0 \"$text_submitted\" ";
Which correctly moves the text to the top, everything is working fine as per the PHP code. HOWEVER, I am wanting to change the appearance of the text that it overlays onto the image, the colorful image is an EXAMPLE of the type of effect I am wanting;

- Text repeated.
- Text oriented.

I have no idea how I need to format the code for it to do that.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Watermarking with Text.

Post by snibgo »

If you want to tile the watermark, then create it as a separate image first, eg (Windows BAT syntax):

Code: Select all

convert ^
  -background None -fill Blue ^
  -pointsize 20 label:snibgo ^
  -rotate -20 +repage ^
  +write mpr:TILE +delete ^
  toes.png -alpha set ^
  ( +clone ^
    -fill mpr:TILE -draw "color 0,0 reset" ^
  ) ^
  -composite ^
  snibtile.jpg
Image
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Watermarking with Text.

Post by fmw42 »

This is unix syntax.

Code: Select all

convert sunset_lake.png \
\( -background none -pointsize 24 -fill white label:"TESTING" -rotate 20 -write mpr:tile +delete \) \
\( +clone -tile mpr:tile -draw "color 0,0 reset" \) \
-compose over -composite sunset_lake_tile_text.png
Image


EDIT: Sorry, snibgo. We were posting at the same time. Almost identical approaches, again.
Watermarked
Posts: 5
Joined: 2017-12-05T20:08:50-07:00
Authentication code: 1152

Re: Watermarking with Text.

Post by Watermarked »

Code: Select all

$cmd = " -size 140x80 xc:none -fill grey -gravity NorthWest ".
" -draw \"text 10,10 \"Copyright\" \" -gravity SouthEast ".
" -draw \"text 5,15 \"Copyright\" \" miff:- | composite ".
" -tile - $original_image ";
exec("convert $cmd $new_image", $array);
Image

Just the rotation I need to do, I am using Imagick with PHP I believe.
Watermarked
Posts: 5
Joined: 2017-12-05T20:08:50-07:00
Authentication code: 1152

Re: Watermarking with Text.

Post by Watermarked »

Completed in my case;

Code: Select all

$cmd = " -size 140x80 xc:none -font /var/www/html/static/fonts/OpenSans-Bold.ttf -fill rgba\(0,0,0,0.4\) -gravity NorthWest ".
" -draw \"text 10,10 \"$text_submitted\" \" -gravity SouthEast ".
" -draw \"text 5,15 \"$text_submitted\" \" miff:- | composite ".
" -tile - $original_image ";
I think I can handle this from here, its been a pleasure. Thank you very much for the assistance, your examples cleared my head up. My mistake was, I was trying to add all of these new -draw lines on the same line, instead of on a new line.
Post Reply