SOLVED:Gradient help

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
Keith Hedger
Posts: 7
Joined: 2011-12-19T06:53:59-07:00
Authentication code: 8675308

SOLVED:Gradient help

Post by Keith Hedger »

Help!!
I have been going round in circles trying to get this to work

Code: Select all

#!/bin/bash -e

Y=38
H=16
X=20

convert -size 500x500 canvas:green -size 1x$H -tile gradient:white-black -draw "rectangle $X,0, 200,$((H-1))" -draw "rectangle 0,$Y, 200,$((H+Y-1))" show:
The first bars gradient is fine but the second is offset I assume the gradient is taken from co-ords 0,0 I just can't find a way to shift it, I need to do this in one command and no temp files/pipes, this is hopefully easy for an imagenagik expert but I just can't sus out how to do it, been googling my a*** off!
Last edited by Keith Hedger on 2011-12-20T13:17:58-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gradient help

Post by fmw42 »

I don't believe that you can do calculations such as $((H-1)) inside the draw. Do them outside as a variable calculation and then just reference the variable.
Keith Hedger
Posts: 7
Joined: 2011-12-19T06:53:59-07:00
Authentication code: 8675308

Re: Gradient help

Post by Keith Hedger »

fmw42 wrote:I don't believe that you can do calculations such as $((H-1)) inside the draw. Do them outside as a variable calculation and then just reference the variable.
In bash $() is command replacement and (()) is c like integer maths so it does the calculation and then substitutes the result so is a valid command line, replacing with constants give the same results.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gradient help

Post by fmw42 »

I stand corrected about the computations.

What is the objective of your command line. Perhaps we can help if we understood further what exactly you are trying to do or see an example. What do you want to do with the tiled gradient with respect to the two draw commands.

Here is what I get by running your command. What is wrong with it? Where do you want the second gradient bar to be located? Without setting -gravity, the default coordinates will be relative to the top left corner as 0,0.


Image


The above should be fine with the right start coordinate and end coordinate for the second gradient. However, with parenthesis processing you can always create your background and two gradients of the size desired and then -compose .. -composite to place them where desired with -geometry. See

http://www.imagemagick.org/Usage/basics/#parenthesis
http://www.imagemagick.org/Usage/layers/#convert
Keith Hedger
Posts: 7
Joined: 2011-12-19T06:53:59-07:00
Authentication code: 8675308

Re: Gradient help

Post by Keith Hedger »

This command line is just a snippet and shows the problem (it is not the finished command line, just the bit I can't get working) with the gradient NOT the bar itself, as you can see by the second gradient it is not the same as the top gradient it starts half way. I need both bars to look the same just in different positions.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Gradient help

Post by anthony »

The -tile command sets an image that you generate as a gradient. by default that image alligns the 0,0 point of the tile with the 0,0 of the canvas when 'drawn'. However you can 'roll' the tile to change this using a -tile-offset setting.

See Canvas Creation, Offset Tiles
http://www.imagemagick.org/Usage/canvas/#tile-offset

NOTE this is equivalent to simply 'rolling' the tile image before it was set using -roll . As such you can DIY that effect yourself using 'Tiling with in-memory image' techniques.
http://www.imagemagick.org/Usage/canvas/#tile_memory

NOTE that tiling a canvas using distorts, also allows you to set tile offsets (and lots more).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gradient help

Post by fmw42 »

Sounds to me simpler to just make two gradient images of the size you want and composite them over the green background. That can be done in one command as mentioned before. See the links at the bottom of my post above.



XOFF=20
YOFF=38
H=16
W1=200
W2=$((W1+XOFF))

convert -size 500x500 canvas:green \
-size ${W1}x${H} gradient: -geometry +20+0 -compose over -composite \
-size ${W2}x${H} gradient: -geometry +0+$YOFF -compose over -composite \
draw_test2.gif

Image
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Gradient help

Post by anthony »

Keith Hedger wrote:This command line is just a snippet and shows the problem (it is not the finished command line, just the bit I can't get working) with the gradient NOT the bar itself, as you can see by the second gradient it is not the same as the top gradient it starts half way. I need both bars to look the same just in different positions.
Perhaps if we can see more of what you are trying to accomplish we can help further.

Do you have a example final image?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Keith Hedger
Posts: 7
Joined: 2011-12-19T06:53:59-07:00
Authentication code: 8675308

Re: Gradient help

Post by Keith Hedger »

THANKS!! fmw42
The -size ${W1}x${H} gradient: -geometry +20+0 -compose over -composite command is exactly what I was looking for, problem solved! :) :) :)
Keith Hedger
Posts: 7
Joined: 2011-12-19T06:53:59-07:00
Authentication code: 8675308

Re: Gradient help

Post by Keith Hedger »

For those who may be interested this is the final result, actually its one screen out of 34 generated by a graphical boot sequence, thanks for the help guys!
Image
P.S.
Can I mark this thread as SOLVED like other forums?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Gradient help

Post by fmw42 »

Withdrawn. At first I could not see your image. I see it now.

Nice image for a holiday card.

To mark as solved, Just edit your title on the first (top most) post and preface with SOLVED:
Keith Hedger
Posts: 7
Joined: 2011-12-19T06:53:59-07:00
Authentication code: 8675308

Re: SOLVED:Gradient help

Post by Keith Hedger »

Cheers! I was looking for a drop down.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: SOLVED:Gradient help

Post by Bonzo »

Yes a good image - so you wanted the gradiant for the loading bar ?
Is the train also an indication of loaded amount?
Keith Hedger
Posts: 7
Joined: 2011-12-19T06:53:59-07:00
Authentication code: 8675308

Re: SOLVED:Gradient help

Post by Keith Hedger »

Bonzo wrote:Yes a good image - so you wanted the gradiant for the loading bar ?
Is the train also an indication of loaded amount?
Yes and what a good idea i will have a look at it when I get time.
Post Reply