Page 1 of 1
SOLVED:Gradient help
Posted: 2011-12-19T09:29:49-07:00
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!
Re: Gradient help
Posted: 2011-12-19T10:46:50-07:00
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.
Re: Gradient help
Posted: 2011-12-19T11:33:56-07:00
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.
Re: Gradient help
Posted: 2011-12-19T14:34:41-07:00
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.
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
Re: Gradient help
Posted: 2011-12-19T16:34:18-07:00
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.
Re: Gradient help
Posted: 2011-12-19T17:23:06-07:00
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).
Re: Gradient help
Posted: 2011-12-19T18:00:51-07:00
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

Re: Gradient help
Posted: 2011-12-19T21:28:05-07:00
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?
Re: Gradient help
Posted: 2011-12-20T04:00:24-07:00
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!

Re: Gradient help
Posted: 2011-12-20T05:50:21-07:00
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!

P.S.
Can I mark this thread as SOLVED like other forums?
Re: Gradient help
Posted: 2011-12-20T11:53:17-07:00
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:
Re: SOLVED:Gradient help
Posted: 2011-12-20T13:18:40-07:00
by Keith Hedger
Cheers! I was looking for a drop down.
Re: SOLVED:Gradient help
Posted: 2011-12-20T13:25:59-07:00
by Bonzo
Yes a good image - so you wanted the gradiant for the loading bar ?
Is the train also an indication of loaded amount?
Re: SOLVED:Gradient help
Posted: 2011-12-21T04:14:29-07:00
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.