Page 1 of 1
[Solved] Shift image 1 pixel to the right, keep size
Posted: 2012-04-22T13:17:48-07:00
by ddrirc
Hi, I'm trying to move all pixels (effectively the whole image) over by one pixel to the right and retain the original size of 120x150.
The below code does ALMOST what I want - it copies the image and moves it over a pixel, but it doesn't get rid of the original image pixels.
Code: Select all
convert test.png -alpha set \( +clone -crop 120x150+0+0 +repage \) \( -clone 0--1 -geometry +1+0 -composite \) -swap 0 +delete \( +clone -alpha opaque \) +swap +delete -gravity east -geometry +119+0 -compose DstOut -composite newtest.png
Any idea how I can fix (or simplify this) to move every pixel over 1 to the right while retaining the 120x150 original size/format?
Thanks!
What I ended up using in the end:
Code: Select all
convert -page +1+0 test.png -background none -flatten newtest.png
Much simpler
Thanks, fmw42
Re: Shift image 1 pixel to the right, keep size
Posted: 2012-04-22T13:29:16-07:00
by fmw42
You can use -roll to shift the image to the right, but it will wrap the rightmost pixel to the left side. Is that what you want to happen? If not
what do you want to be on the left side of the image? You can insert a color if you want using -compose over -composite.
see
http://www.imagemagick.org/script/comma ... eilg1#roll
Alternately, you can crop the image and just mosaic or flatten or composite over some background color or background image, which could be a color or the image itself. Mosaic will expand the canvas.
see
http://www.imagemagick.org/Usage/layers/#mosaic
http://www.imagemagick.org/Usage/layers/#flatten
Another approach is to use -virtual-pixel .... -define distort:viewport=... -distort SRT 0 to shift the image
The virtual-pixel setting will control what fills in the left side.
see
http://www.imagemagick.org/Usage/distor ... t_viewport
Re: Shift image 1 pixel to the right, keep size
Posted: 2012-04-22T13:40:48-07:00
by ddrirc
I actually want the furthest right pixel to just be lost, no wrapping. And the background needs to remain transparent/alpha so I'm not sure how well flattening would work
Re: Shift image 1 pixel to the right, keep size
Posted: 2012-04-22T13:42:26-07:00
by fmw42
ddrirc wrote:I actually want the furthest right pixel to just be lost, no wrapping. And the background needs to remain transparent/alpha so I'm not sure how well flattening would work
So you want to drop the right column and fill the left with transparency? Is that correct?
Try this:
convert rose: rose.png
convert -page +1+0 rose: -background none -flatten rose_tmp.png
Then alternate each image to see that it is shifted to the right and the same size.
Re: Shift image 1 pixel to the right, keep size
Posted: 2012-04-22T13:47:48-07:00
by ddrirc
fmw42 wrote:ddrirc wrote:I actually want the furthest right pixel to just be lost, no wrapping. And the background needs to remain transparent/alpha so I'm not sure how well flattening would work
So you want to drop the right column and fill the left with transparency? Is that correct?
Try this:
convert rose: rose.png
convert -page +1+0 rose: -background none -flatten rose_tmp.png
Then alternate each image to see that it is shifted to the right and the same size.
Works perfectly, thank you!
Re: [Solved] Shift image 1 pixel to the right, keep size
Posted: 2012-04-22T20:06:48-07:00
by anthony
Subject: [Solved] Shift image 1 pixel to the right, keep size
ddrirc wrote:What I ended up using in the end:
Code: Select all
convert test.png -page +1+0 -background none -flatten newtest.png
Much simpler
Thanks, fmw42
Note that that will fail!
-page is for setting virtual canvas size/offset BEFORE they are read. While
-repage is for image already in memory, AFTER they have been read.
Re: [Solved] Shift image 1 pixel to the right, keep size
Posted: 2012-04-22T20:34:32-07:00
by fmw42
Anthony is right. That is not what I wrote above:
convert -page +1+0 rose: -background none -flatten rose_tmp.png
Re: [Solved] Shift image 1 pixel to the right, keep size
Posted: 2012-04-23T02:55:27-07:00
by ddrirc
Really? I get no error and it seems to do the job, but I will switch the order if you say so.
Re: [Solved] Shift image 1 pixel to the right, keep size
Posted: 2012-04-23T10:09:01-07:00
by fmw42
ddrirc wrote:Really? I get no error and it seems to do the job, but I will switch the order if you say so.
or try
convert test.png
-repage +1+0 -background none -flatten newtest.png
see
http://www.imagemagick.org/Usage/layers/#flatten for use of -page
also see for repage
http://www.imagemagick.org/Usage/basics/#page