Hello all,
First time poster to the forums, but long time user of ImageMagick.
I'm trying to come up with a command line to take a TIFF image, and shift either the bottom half, or the top half of an image a set number of pixels. This move might be an upward shift in some cases, but there are other cases where I need to make this a downward shift.
Here's a very simple example image (.jpg image used for to simplify for web viewing):
Basically what I want to do here is split the image in half horizontally, then apply say a 10px shift of the bottom half downward (so that the bottom text moves down 10px, while not affecting the top text). However, while at the same time keeping the same original size dimensions of the image, and also keeping the grey background consistent throughout the entire image - including the new "empty space" where the split took place.
Many thanks in advance!
Shift bottom or top portion of image?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Shift bottom or top portion of image?
color=`convert test.jpg[1x1+0+0] -format "rgb(%[fx:floor(255*u.g)],%[fx:floor(255*u.r)],%[fx:floor(255*u.b)])" info:`
convert test.jpg -background $color -gravity center -splice 0x10 -gravity south -chop 0x10 test2.jpg
see
http://www.imagemagick.org/Usage/crop/#splice
http://www.imagemagick.org/Usage/crop/#chop
convert test.jpg -background $color -gravity center -splice 0x10 -gravity south -chop 0x10 test2.jpg
see
http://www.imagemagick.org/Usage/crop/#splice
http://www.imagemagick.org/Usage/crop/#chop
Re: Shift bottom or top portion of image?
fmw42 wrote:color=`convert test.jpg[1x1+0+0] -format "rgb(%[fx:floor(255*u.g)],%[fx:floor(255*u.r)],%[fx:floor(255*u.b)])" info:`
convert test.jpg -background $color -gravity center -splice 0x10 -gravity south -chop 0x10 test2.jpg
see
http://www.imagemagick.org/Usage/crop/#splice
http://www.imagemagick.org/Usage/crop/#chop
Many thanks for the quick reply! I just copied the command into a batch file, and ran it on my test image. And while it does move the bottom portion of the image down 10px, it leaves a 10px black strip across the center of the image. Any way to make it perform the function, AND to keep the background color intact in the spliced area?
Re: Shift bottom or top portion of image?
Sorry, I posted my reply too quickly without looking at the command. I do see the "-background $color" section of the command, and I also see the entire first line of the command looks like it's attempting to grab the background color from the original image.fmw42 wrote:color=`convert test.jpg[1x1+0+0] -format "rgb(%[fx:floor(255*u.g)],%[fx:floor(255*u.r)],%[fx:floor(255*u.b)])" info:`
convert test.jpg -background $color -gravity center -splice 0x10 -gravity south -chop 0x10 test2.jpg
see
http://www.imagemagick.org/Usage/crop/#splice
http://www.imagemagick.org/Usage/crop/#chop
I might add however, that I'm testing this on a Windows install of ImageMagick using batch files, rather than a Unix/Linux environment. So I'm not sure that the $color variable is being set when executing the command, which is why I'm getting the black bar across the middle.
I attempted the command hard-coding the background using "-background #989a90" And this does work, but I would ideally like to have the background color selected by ImageMagick using a variable like the originally provided code.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Shift bottom or top portion of image?
Yes, the first line gets the color of the upper left corner pixel of the image.
Here is a shorter way:
color=`convert test.jpg -format "%[pixel:s.p{0,0}]" info:`
You can change the pixel to any location you want. See http://www.imagemagick.org/Usage/transform/#fx_escapes
I am not a Windows expert or user, but try doubling the % to %%. I am not sure how you handle the $ in $color, you may have to use %color or put in quotes as "$color", but see below. Hopefully a Windows user can set you straight on that, if none of this works.
see http://www.imagemagick.org/Usage/api/#windows
"Also in DOS batch files any percent '%' characters may need to be doubled '%%' to work correctly. This is because in DOS '%' is used to prefix variable substitution. Unix scripts use '$' for variable substition."
Here is a shorter way:
color=`convert test.jpg -format "%[pixel:s.p{0,0}]" info:`
You can change the pixel to any location you want. See http://www.imagemagick.org/Usage/transform/#fx_escapes
I am not a Windows expert or user, but try doubling the % to %%. I am not sure how you handle the $ in $color, you may have to use %color or put in quotes as "$color", but see below. Hopefully a Windows user can set you straight on that, if none of this works.
see http://www.imagemagick.org/Usage/api/#windows
"Also in DOS batch files any percent '%' characters may need to be doubled '%%' to work correctly. This is because in DOS '%' is used to prefix variable substitution. Unix scripts use '$' for variable substition."
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Shift bottom or top portion of image?
please note that in
color=`convert test.jpg -format "%[pixel:s.p{0,0}]" info:`
those are not single quotes, but slanted quotes required by Unix. I don't know what the Windows equivalent of that is to define a variable from an IM command result.
color=`convert test.jpg -format "%[pixel:s.p{0,0}]" info:`
those are not single quotes, but slanted quotes required by Unix. I don't know what the Windows equivalent of that is to define a variable from an IM command result.