Cut 3 pixels from the end of image and join it to the front

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
joshiishan
Posts: 6
Joined: 2018-05-10T08:00:26-07:00
Authentication code: 1152

Cut 3 pixels from the end of image and join it to the front

Post by joshiishan »

Hi guys,

I am a new user.

I need to bulk edit images as the legacy image exporter gives me weirdly broken images.
Image
Image
Image
Image
Image
Image
Image
Image

I need to cut 3px from the end of the image and join it to the front with 1px up-shift.

Can someone please guide me on how can I make this happen? Even a small direction would help...

I know there are no free lunches, so I am willing to buy a beer to the one who helps me out! :wink:

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

Re: Cut 3 pixels from the end of image and join it to the front

Post by snibgo »

Code: Select all

magick VP_EQN_7.gif -roll -3+0 x.png
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Cut 3 pixels from the end of image and join it to the front

Post by GeeMack »

joshiishan wrote: 2018-05-10T08:15:47-07:00I need to cut 3px from the end of the image and join it to the front with 1px up-shift.

Can someone please guide me on how can I make this happen? Even a small direction would help...
You could use a simple "-roll" operation except you need to shift that last 3 pixel wide section up one, so it has to be handled separately. A command like this should work with IM6 in a *nix shell or script...

Code: Select all

convert input.gif -gravity northeast -background white \
 \( -clone 0 -crop 3x0+0+1 -duplicate 1 \) -reverse +append -shave 0x3 output.gif
You would use "magick" instead of "convert" if you're using IM7. If you're working from a Windows command line or BAT script you need to remove those backslashes that escape the parentheses and replace the continued line backslash "\" with a caret "^"..

To do a batch conversion, use a command like that in a "for" loop to process all the files. Exactly how to do that depends on what sort of system you're running it on.
I know there are no free lunches, so I am willing to buy a beer to the one who helps me out! :wink:
joshiishan
Posts: 6
Joined: 2018-05-10T08:00:26-07:00
Authentication code: 1152

Re: Cut 3 pixels from the end of image and join it to the front

Post by joshiishan »

Hi GeekMack,
GeeMack wrote: 2018-05-10T16:14:27-07:00

Code: Select all

convert input.gif -gravity northeast -background white \
 \( -clone 0 -crop 3x0+0+1 -duplicate 1 \) -reverse +append -shave 0x3 output.gif
I am using ubuntu with imagemagic 6.9.7-4.

I tried the command

Code: Select all

convert _VP_EQN_6.GIF -gravity northeast -background white \( -clone 0 -crop 3x0+0+1 -duplicate 1 \) -reverse +append -shave 0x3 output.gif
It generates this image: Image

It seems the 1 on the right side of the image is stamped on the left and the whole image is reduced by 1px :(

You got it right that the -roll won't work as I just need to vertical shift the last 3px part of the image and then roll the image. I am new to the scripting so I was not able to play much with the script though, I am trying and reading the help.

Noted:
I know there are no free lunches, so I am willing to buy a beer to the one who helps me out! :wink:
Thanks a lot,
Ishan
joshiishan
Posts: 6
Joined: 2018-05-10T08:00:26-07:00
Authentication code: 1152

Re: Cut 3 pixels from the end of image and join it to the front

Post by joshiishan »

Hi GeekMack,

I got the desired result using

Code: Select all

convert _VP_EQN_1.GIF -gravity northeast \( -clone 0 -crop 3x0+0x0 -duplicate 1 -roll +0-1 \) -reverse +append -shave 3x0 output.png
.

Please let me know how to buy you a beer!

Thanks a lot for the direction.

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

Re: Cut 3 pixels from the end of image and join it to the front

Post by GeeMack »

joshiishan wrote: 2018-05-10T17:52:20-07:00I got the desired result using

Code: Select all

convert _VP_EQN_1.GIF -gravity northeast \( -clone 0 -crop 3x0+0x0 -duplicate 1 -roll +0-1 \) -reverse +append -shave 3x0 output.png
.
Looks like your "-crop" argument should be "+0+0", with a "+" instead of that "x".
Please let me know how to buy you a beer!
PayPal: gmcneil@mtco.com
Post Reply