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?".
n0_namer
Posts: 5
Joined: 2017-02-03T09:44:24-07:00
Authentication code: 1151

Re: Proportional watermark

Post by n0_namer » 2017-02-04T08:21:10-07:00

I tried this variant. It takes a height of the watermark.png but I need to take a height of the input.png.

User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Proportional watermark

Post by fmw42 » 2017-02-04T11:00:58-07:00

In IM 7, this gets 1/5 of the input image height and resizes the watermark image to that size.

Code: Select all

magick input.png -set option:wmh "%[fx:h/5]" ( watermark.png -resize x%[wmh] ) -gravity center -composite result.png

n0_namer
Posts: 5
Joined: 2017-02-03T09:44:24-07:00
Authentication code: 1151

Re: Proportional watermark

Post by n0_namer » 2017-02-04T14:46:29-07:00

Works perfect. Thanks, snibgo.

User avatar
fmw42
Posts: 22105
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Proportional watermark

Post by fmw42 » 2017-02-04T14:57:49-07:00

I am not snibgo

fghhfg
Posts: 2
Joined: 2017-10-16T05:50:32-07:00
Authentication code: 1151

Re: Proportional watermark

Post by fghhfg » 2017-10-16T06:03:07-07:00

A version:

Code: Select all

magick input.png ( watermark.png -resize x%[fx:u[0].h/5] ) -gravity center -composite result.png
this is wrong, but it is faster than b version.

B version:

Code: Select all

magick input.png -set option:wmh "%[fx:h/5]" ( watermark.png -resize x%[wmh] ) -gravity center -composite result.png
now I want to speedup, so I use "-sample" instead of "-resize".
The"-sample" of B version is still faster than the "-sample" of A version. (x1.55 times)

For this reason, you may want to use the wrong version if possible...

the "Image Stack" or "-set" cost a lot of speed...
How do I speedup on corrected version?

my code (IM7):

Code: Select all

find a -type f -name "*.jpg" -print0 | xargs -0 -n1 -P8 -I {} magick {} -set option:wmh %[fx:w/2] ( mark2.png -sample %[wmh]x ) -gravity east -compose dissolve -define compose:args=60 -composite {}

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

Re: Proportional watermark

Post by GeeMack » 2017-10-16T07:21:11-07:00

fghhfg wrote:
2017-10-16T06:03:07-07:00
How do I speedup on corrected version?
I don't know much about the internals, but if there's something about setting and reading a variable that slows the command, you could try writing the FX calculation as an inline argument to the "-resize" operation. A command like this should give you the result you're looking for. You'll have to test it yourself for speed comparison.

Code: Select all

magick input.png watermark.png -resize "x%[fx:t?u[0].h/5:u[0].h]" -gravity center -composite result.png
The FX expression there will only resize the second image in the stack, which is the watermark. Otherwise it leaves the size unchanged.

fghhfg
Posts: 2
Joined: 2017-10-16T05:50:32-07:00
Authentication code: 1151

Re: Proportional watermark

Post by fghhfg » 2017-10-16T10:35:21-07:00

ternary operator, nice try, but it has same speed as `"Image Stack" + "-set"`

OK, I accept this result.

Now I believe the reason b version spend few time just because it deals few pixels.

nothing wrong inside IM.

I find xnconvert faster than IM though.

Post Reply