Page 1 of 1

Watermarking with Text.

Posted: 2017-12-05T20:29:15-07:00
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.

Re: Watermarking with Text.

Posted: 2017-12-05T20:38:49-07:00
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?

Re: Watermarking with Text.

Posted: 2017-12-05T20:44:07-07:00
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.

Re: Watermarking with Text.

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

The colourful rectangular image seems to have no text.

Re: Watermarking with Text.

Posted: 2017-12-05T20:59:39-07:00
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.

Re: Watermarking with Text.

Posted: 2017-12-05T21:38:35-07:00
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

Re: Watermarking with Text.

Posted: 2017-12-05T21:42:24-07:00
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.

Re: Watermarking with Text.

Posted: 2017-12-05T21:45:51-07:00
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.

Re: Watermarking with Text.

Posted: 2017-12-05T22:02:11-07:00
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.

Re: Watermarking with Text.

Posted: 2020-03-05T00:27:46-07:00
by modia
Hi,
I have used the following line of code in image magick version 6.9.2.6:

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
And my output file has changed completely. The background has changed to pink and the "TESTING" text is written in White colour which is in black box.

Re: Watermarking with Text.

Posted: 2020-03-05T00:36:26-07:00
by fmw42
What version of ImageMagick and what version of libpng? It works fine for me on IM 6.9.10.97 Q16 Mac OSX

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

Re: Watermarking with Text.

Posted: 2020-03-05T00:58:53-07:00
by modia
I am using IM 6.9.2.6.
I am not able to attach my output file here. It would be great if you can help me out with that.
The code which you have added is it like this?

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

I am using windows cmd to run the above code and it has thrown following error:
convert.exe: UnableToOpenBlob `\)': No such file or directory @ error/blob.c/OpenBlob/2701.
convert.exe: NoDecodeDelegateForThisImageFormat `' @ error/constitute.c/ReadImage/501.
convert.exe: UnableToOpenBlob `\\(': No such file or directory @ error/blob.c/OpenBlob/2701.
convert.exe: NoDecodeDelegateForThisImageFormat `' @ error/constitute.c/ReadImage/501.
convert.exe: UnableToOpenBlob `\)': No such file or directory @ error/blob.c/OpenBlob/2701.
convert.exe: NoDecodeDelegateForThisImageFormat `' @ error/constitute.c/ReadImage/501.

Re: Watermarking with Text.

Posted: 2020-03-05T01:33:12-07:00
by fmw42
No, you have too many \ for one line. My extra backslashes were for end of line markers to split the command to several lines. If you want only one long command line, then use

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
Sorry, IM 6.9.2.6 is too ancient for my system to run due to delegate version mismatches. I would urge you to upgrade ImageMagick. You could just have a bug in that version or your PNG delegate is too old or buggy.

Re: Watermarking with Text.

Posted: 2020-03-05T02:49:46-07:00
by modia
Now , i have upgraded the image magick to IM 7.0.8 and I have used your above mentioned code.
This time the output file is rotated with certain degree.
As i am not able to add the image file here, i am adding the drive link which has both input and output files:
https://drive.google.com/open?id=1jq4nR ... -xek9TBVW2

Re: Watermarking with Text.

Posted: 2020-03-05T07:49:41-07:00
by GeeMack
modia wrote:
2020-03-05T00:58:53-07:00
I am using windows cmd to run the above code...
For Windows you'll need to remove all those backslashes "\" that escape parentheses. Make these "\(" and "\)" into these "(" and ")".