Proportional watermark

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?".
c68gsrwztve6
Posts: 6
Joined: 2016-11-18T15:55:23-07:00
Authentication code: 1151

Proportional watermark

Post by c68gsrwztve6 »

Hellow everybody!

I have a very simple and common question and was surprised when I could not find the examples in the docs neither any info on the forum.

I have a bunch of images of absolutely different sizes (100x500, 5000x4475, 200x300, 1280x1068 etc.). And I have one watermark image which is 700x100.

The question is - how can I set this watermark on every of those pics:
a) keeping the original size of the photo
b) keeping the watermark's width always 100% of the processed photo's width (e.g. when the photo is 100x500 the wm's width is 100, when the photo is 5000x4475 the wm's width is 5000, when the photo is 200x300 the wm's width is 200 etc).

Thanks in advance
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Proportional watermark

Post by GeeMack »

c68gsrwztve6 wrote:I have a very simple and common question and was surprised when I could not find the examples in the docs neither any info on the forum.
This is a common sort of process for IM. The choice of specific techniques would depend on your operating system or platform, your version of IM, and whether you want to run this command on a single file or maybe on entire directories of tens, hundreds, or thousands of images at a time. Give us a little more information, and maybe any commands you've already tried.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Proportional watermark

Post by snibgo »

Another piece of information is needed: what should happen to the height of the watermark? Should that resize in the same proportion as the width, or should its height be constant?
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: Proportional watermark

Post by fmw42 »

Also if the height scales bigger than your input image, then what do you want to happen -- center align and crop it off?
c68gsrwztve6
Posts: 6
Joined: 2016-11-18T15:55:23-07:00
Authentication code: 1151

Re: Proportional watermark

Post by c68gsrwztve6 »

Thank you very much for your feedback!
GeeMack wrote: operating system or platform, your version of IM, and whether you want to run this command on a single file or maybe on entire directories of tens, hundreds, or thousands of images at a time
OS Windows 8.1
version of IM - 7, but I think I could get 6 if needed
single or thousands - now it is one or couple of files at a time (<=10), but it would be great to have solutions for both cases (for <=10 and for =>10000), 'cause in a while the number could be increased.
snibgo wrote:what should happen to the height of the watermark? Should that resize in the same proportion as the width, or should its height be constant?
in the same proportion as the width. The view of the wm should be always the same, so its aspect ratio is constant.
fmw42 wrote:Also if the height scales bigger than your input image, then what do you want to happen -- center align and crop it off?
Does IM allow to have the wm's height always equal or less 1/4 of an image's height?

A little clarifying for my question:
c68gsrwztve6 wrote:The question is - how can I set this watermark on every of those pics:
a) keeping the original size of the photo
b) keeping the watermark's width always 100% of the processed photo's width
The solution must respond both conditions ( a) AND b), not a) OR b) )
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Proportional watermark

Post by GeeMack »

c68gsrwztve6 wrote:The question is - how can I set this watermark on every of those pics:
a) keeping the original size of the photo
b) keeping the watermark's width always 100% of the processed photo's width (e.g. when the photo is 100x500 the wm's width is 100, when the photo is 5000x4475 the wm's width is 5000, when the photo is 200x300 the wm's width is 200 etc).
Let's say your watermark image is already partially transparent. Using IM7 on Windows, something like this run from the command line will take a single input file and overlay the watermark.

Code: Select all

magick input.png watermark.png -resize %[fx:u[0].w]x -gravity center -composite result.png
This command will resize the watermark so its width matches the width of the input image, then it composites the watermark centered over the input image. If the watermark resizes larger than the height of the input image, any excess will just be discarded.

Something like this can be run on a whole directory with hundreds or maybe thousands of images, depending on the memory and speed of your computers and the image sizes. The watermark can be resized, height and/or width, to any size relative to any of the input image's dimensions.
c68gsrwztve6
Posts: 6
Joined: 2016-11-18T15:55:23-07:00
Authentication code: 1151

Re: Proportional watermark

Post by c68gsrwztve6 »

GeeMack wrote:

Code: Select all

magick input.png watermark.png -resize %[fx:u[0].w]x -gravity center -composite result.png
Excellent!!! It works!
Very appreciate your help!
c68gsrwztve6
Posts: 6
Joined: 2016-11-18T15:55:23-07:00
Authentication code: 1151

Re: Proportional watermark

Post by c68gsrwztve6 »

Hi, guys!
It's me again!

Another little question about the code above.

Is there any way to make it work in silent mode? Without splashing black window.

OS Windows 8.1

It looked at
https://www.imagemagick.org/script/comm ... .php#quiet
but there is no examples. I tried to insert -quiet at random places but that didn't work.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Proportional watermark

Post by snibgo »

c68gsrwztve6 wrote:Is there any way to make it work in silent mode? Without splashing black window.
How are you running it? I suggest you use a command window, aka "console". (This is a black window (or whatever colour you want) with a command prompt.)
snibgo's IM pages: im.snibgo.com
c68gsrwztve6
Posts: 6
Joined: 2016-11-18T15:55:23-07:00
Authentication code: 1151

Re: Proportional watermark

Post by c68gsrwztve6 »

snibgo wrote:How are you running it? I suggest you use a command window, aka "console". (This is a black window (or whatever colour you want) with a command prompt.)
My app calls the cmd and send there the IM command. That's why the command window splashes every time it is called. I need some echo suppressing command in IM to keep the cmd invisible. Something like the "/silent" command in irfan.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Proportional watermark

Post by snibgo »

On MS Windows, IM magick.exe (etc) is a "console" program, not a "windows" program. Console programs have the usual Unix-like facilities for stdin, stdout etc. If you call it from a program that doesn't have a console, the Windows operating system will create a console for it.

There are ways of telling Windows to start a console program but without the console. I'm not an expert on that.
snibgo's IM pages: im.snibgo.com
c68gsrwztve6
Posts: 6
Joined: 2016-11-18T15:55:23-07:00
Authentication code: 1151

Re: Proportional watermark

Post by c68gsrwztve6 »

snibgo wrote:I'm not an expert on that.
Me neither unfortunately. But there are some ways in programs to tell OS not to create the window (like irfan and its /silent). Maybe IM have such command?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Proportional watermark

Post by snibgo »

No, it would be up to the caller (your app) to tell Windows not to create a console.
snibgo's IM pages: im.snibgo.com
n0_namer
Posts: 5
Joined: 2017-02-03T09:44:24-07:00
Authentication code: 1151

Re: Proportional watermark

Post by n0_namer »

Hello, I was trying to modify the code to make watermark always 1/6 height of input.png. It makes watermark smaller, but it also makes the input.png 1/6 of its height. Where have I made a mistake? I'm using Windows 10 x64 and IM 7.0.4-Q16.

Code: Select all

magick input.png watermark.png -resize x%[fx:u[0].h/5] -gravity center -composite result.png
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Proportional watermark

Post by snibgo »

Code: Select all

magick input.png ( watermark.png -resize x%[fx:u[0].h/5] ) -gravity center -composite result.png
snibgo's IM pages: im.snibgo.com
Post Reply