Replace solid color with oriented gradient

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
Tyvain
Posts: 2
Joined: 2013-06-03T07:27:32-07:00
Authentication code: 6789

Replace solid color with oriented gradient

Post by Tyvain »

Hello all,

I am trying to make a script to replace a color from an image with a gradient oriented one. The goal is make an animated image with the gradient color turning.
I try diffrent commands but was unable to do it. My main problem is that this command "convert source.jpg -size 1000x496 gradient:yellow-green -opaque "#0973A5" res2.jpg" create a square gradient, and not a gradient replacing the given color.

here is my source image: Image
here is what i would like to have in result (the angle of the gradient can change): Image

i someone can help please.

Sorry if my english is not very good.

Thank you.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replace solid color with oriented gradient

Post by snibgo »

I would break the problem down into stages. One stage is to replace the solid blue with a gradient blue. You can create the gradient blue (Windows script), at any angle you want:

Code: Select all

convert -size 140x140 gradient:rgb(0,0,64)-rgb(200,200,255) -rotate 45 +repage grad1.png
I will make the solid blue transparent, and overlay the result over the gradient. But the background is already transparent, so I will first make that red.

Code: Select all

convert ring.png ( +clone -fill Red -colorize 100 ) +swap -composite rNT.png

set COL1=rgb(0,147,238)

convert rNT.png -transparent %COL1% r2.png

convert grad1.png r2.png -gravity center -composite -crop 96x96+0+0 +repage r.png
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: Replace solid color with oriented gradient

Post by fmw42 »

removed -- misread the issue
Tyvain
Posts: 2
Joined: 2013-06-03T07:27:32-07:00
Authentication code: 6789

Re: Replace solid color with oriented gradient

Post by Tyvain »

snibgo wrote:I would break the problem down into stages. One stage is to replace the solid blue with a gradient blue. You can create the gradient blue (Windows script), at any angle you want:

Code: Select all

convert -size 140x140 gradient:rgb(0,0,64)-rgb(200,200,255) -rotate 45 +repage grad1.png
I will make the solid blue transparent, and overlay the result over the gradient. But the background is already transparent, so I will first make that red.

Code: Select all

convert ring.png ( +clone -fill Red -colorize 100 ) +swap -composite rNT.png

set COL1=rgb(0,147,238)

convert rNT.png -transparent %COL1% r2.png

convert grad1.png r2.png -gravity center -composite -crop 96x96+0+0 +repage r.png
wow thank you very much!!
this is working great and do exactly what i need!!
king111
Posts: 2
Joined: 2016-02-19T06:30:23-07:00
Authentication code: 1151

Re: Replace solid color with oriented gradient

Post by king111 »

snibgo wrote:I would break the problem down into stages. One stage is to replace the solid blue with a gradient blue. You can create the gradient blue (Windows script), at any angle you want:

Code: Select all

convert -size 140x140 gradient:rgb(0,0,64)-rgb(200,200,255) -rotate 45 +repage grad1.png
I will make the solid blue transparent, and overlay the result over the gradient. But the background is already transparent, so I will first make that red.

Code: Select all

convert ring.png ( +clone -fill Red -colorize 100 ) +swap -composite rNT.png

set COL1=rgb(0,147,238)

convert rNT.png -transparent %COL1% r2.png

convert grad1.png r2.png -gravity center -composite -crop 96x96+0+0 +repage r.png
Can you tell all the steps for PHP ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Replace solid color with oriented gradient

Post by snibgo »

Put each "convert" command in an exec().
snibgo's IM pages: im.snibgo.com
Post Reply