How to build this effect in Image Magick?

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
pimboli
Posts: 5
Joined: 2018-10-04T19:10:53-07:00
Authentication code: 1152

How to build this effect in Image Magick?

Post by pimboli »

Hi,

can someone please tell me how can I create this effect in imageMagick?

2 images, one as overlay with a gradient in the middle over the first image.

Image

Thank you in advance.

Pim.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to build this effect in Image Magick?

Post by fmw42 »

Unix syntax:

Code: Select all

convert image1 image2 \( -clone 1 -channel rgba -alpha transparent -sparse-color barycentric '0,0 white  %w,0 black' \) -compose over -composite result
See
https://imagemagick.org/Usage/canvas/#t ... _gradients
https://imagemagick.org/Usage/compose/#compose

________

Please, always provide your IM version and platform when asking questions, since syntax may differ.

Also provide your exact command line and your images, if possible.

See the top-most post in this forum "IMPORTANT: Please Read This FIRST Before Posting" at http://www.imagemagick.org/discourse-se ... f=1&t=9620

If using Imagemagick 7, then see http://imagemagick.org/script/porting.php#cli


For novices, see

http://www.imagemagick.org/discourse-se ... f=1&t=9620
http://www.imagemagick.org/script/comma ... essing.php
http://www.imagemagick.org/Usage/reference.html
http://www.imagemagick.org/Usage/
https://github.com/ImageMagick/usage-markdown
pimboli
Posts: 5
Joined: 2018-10-04T19:10:53-07:00
Authentication code: 1152

Re: How to build this effect in Image Magick?

Post by pimboli »

Thank you @fmw42 for your reply and your explications, wow I would like to have your IM skills :)

I am on IM7 on OSx:
convert --version
Version: ImageMagick 7.0.8-11 Q16 x86_64 2018-09-08 https://www.imagemagick.org

The command that you gave me does not work, I suppose it's related to IM7?

I tried with:

Code: Select all

convert 1.jpg 2.jpg \( -clone 1 -channel rgba -alpha transparent -sparse-color barycentric '0,0 white  %w,0 black' \) -compose over -composite result.jpg
In the result.jpg I only see 2.jpg ass output.
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: How to build this effect in Image Magick?

Post by GeeMack »

pimboli wrote: 2018-10-05T04:49:10-07:00I am on IM7 on OSx:
convert --version
Version: ImageMagick 7.0.8-11 Q16 x86_64 2018-09-08 https://www.imagemagick.org

The command that you gave me does not work, I suppose it's related to IM7?
If you're using IM7 you should be using the command "magick" instead of "convert".

This command is nearly the same as fmw42's, and it works for me using "convert" with IM 6.8.9-9 in a bash shell. Also, by eliminating the backslashes "\" it works with IM 6.9.10-11 in Windows, and by using "magick" with IM 7.0.8-12 in Windows...

Code: Select all

magick in1.jpg in2.jpg ( -clone 0 -sparse-color barycentric "0,0 black %[w],0 white" ) -composite out.jpg
If it doesn't work, maybe you can upload your input images to a public server so we can test them to find the source of your problem.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to build this effect in Image Magick?

Post by fmw42 »

Yes, I believe Windows requires double quotes and as Geemack said remove the \s from my command and for IM 7 use magick not convert.
pimboli
Posts: 5
Joined: 2018-10-04T19:10:53-07:00
Authentication code: 1152

Re: How to build this effect in Image Magick?

Post by pimboli »

Thanks guys I really appreciate your help!

I have no success..

Code: Select all

magick 1.jpg 2.jpg \( -clone 1 -channel rgba -alpha transparent -sparse-color barycentric '0,0 white  %w,0 black' \) -compose over -composite result.jpg
still gets me as result the 2.jpg

I even tried with magick instead of convert due to the facts that I am on IM7.

I think I need to \ the "(" on mac (its a bash shell).
If I run command without / I get an error:
bash-3.2$ magick 1.jpg 2.jpg ( -clone 1 -channel rgba -alpha transparent -sparse-color barycentric '0,0 white %w,0 black' ) -compose over -composite result.jpg
bash: syntax error near unexpected token `('
Here are the input images and the result.jpg:

https://imgur.com/a/8Y2mIsU

As you can see result.jpg = 2.jpg but not the required effect.
pimboli
Posts: 5
Joined: 2018-10-04T19:10:53-07:00
Authentication code: 1152

Re: How to build this effect in Image Magick?

Post by pimboli »

I tried now on a linux vps with IM 6,
and there it seems to work with convert instead of magick.

https://imgur.com/a/8Y2mIsU => look at result_linux.jpg.

In worst-case I could let run the script later under linux.

Could please tell me if you know how I could make the beginning and the end of the image "un-transparent" and only the middle part transparent gradient.

How I would like to have the image:
Image

my result under linux:
Image

Thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to build this effect in Image Magick?

Post by fmw42 »

Could please tell me if you know how I could make the beginning and the end of the image "un-transparent" and only the middle part transparent gradient.
How much of the ends and middle? 1/3, 1/3, 1/3? or some other portions?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to build this effect in Image Magick?

Post by snibgo »

snibgo's IM pages: im.snibgo.com
pimboli
Posts: 5
Joined: 2018-10-04T19:10:53-07:00
Authentication code: 1152

Re: How to build this effect in Image Magick?

Post by pimboli »

fmw42 wrote: 2018-10-05T11:02:08-07:00
Could please tell me if you know how I could make the beginning and the end of the image "un-transparent" and only the middle part transparent gradient.
How much of the ends and middle? 1/3, 1/3, 1/3? or some other portions?
Yes 1/3, 1/3 , 1/3 would be good I think so.
If you could give me the command I can adapt it in case I would like to change the proportions.

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

Re: How to build this effect in Image Magick?

Post by GeeMack »

pimboli wrote: 2018-10-05T11:11:06-07:00Yes 1/3, 1/3 , 1/3 would be good I think so.
If you could give me the command I can adapt it in case I would like to change the proportions.
In the example commands above there's a section inside parentheses. That's where you're creating the mask for the gradient overlay. You can use FX expressions in that "-sparse-color" operation to make the black and white start and end wherever you like. Here's a way to make that mask for a 1/3 solid first image, 1/3 fade to second image, and end with a 1/3 solid second image...

Code: Select all

... \( -clone 0 -sparse-color barycentric "%[fx:w*0.333],0 black %[fx:w*0.667],0 white" \) ...
Those FX expressions are calculating some amount of the width of the image, "w*0.333". Adjust them to suit your need. Learn more about using FX expressions at THIS link.
Post Reply