My PNG image seems to be shifted down by 1 pixel (compared to what it is supposed to be). I thought this would be an easy fix (to just move the image up by a pixel) except I cant seem to drag it up because there are no extra pixels on the bottom to lose. I can cut away the extra pixel at the top, but then my image is one pixel smaller than it needs to be. My default editor, MS Paint, cant even edit it at all because it is "too small to edit: we cant edit anything smaller than 50 pixels. After about an hour of trying with "Paint 3D" and various online editors I've given up and come here. If anyone knows any ways to add a row of pixels to the bottom that would work too.
CodePudding user response:
You can use ImageMagick on Windows, macOS and Linux, in Terminal as follows. I'll use this image with a red, single pixel border.
Chop a row of pixels off the top of an image:
magick mogrify -gravity north -chop x1 image.png
Chop a row of pixels off the bottom of an image:
magick mogrify -gravity south -chop x1 image.png
Splice a row of yellow pixels onto top of image:
magick mogrify -gravity north -background yellow -splice x1 image.png
Splice a row of magenta pixels onto bottom of image:
magick mogrify -gravity south -background magenta -splice x1 image.png
Just for completeness, chop a column of pixels off the right side:
magick mogrify -gravity east -chop 1x image.png
And, add a column of cyan pixels to the right side:
magick mogrify -gravity east -background cyan -splice 1x image.png
Note that all the commands above are done "in situ", which overwrites the input image, and saves you having to specify the same filename for both input and output. It also allows you to use wildcards to specify lots of images, like this:
magick mogrify -gravity north -chop x1 *.png *.jpg
If, however, you want to avoid overwriting the input image, change from this format:
magick mogrify -gravity north -chop x1 image.png
to this format which processes a single input image and saves the result under a different name:
magick INPUT.PNG -gravity north -chop x1 OUTPUT.PNG
Or, if you want to do lots of images at once, i.e. using mogrify
and wildcards, but do not want to overwrite your original images, you can use mogrify
and also make and use an output directory:
mkdir OUTPUT
magick mogrify -path OUTPUT -gravity north -chop x1 *.png *.jpg
Note that you can combine any/all of the above, so if you want to start with the original image at the beginning of the answer, and slice a line off the top and add a line of lime green at the bottom:
magick image.png -gravity north -chop x1 -gravity south -background lime -splice x1 result.png
CodePudding user response:
You can duplicate the last row of pixels in ImageMagick and then append it to the bottom.
Unix syntax:
convert image.png \( clone -gravity south -crop x1 0 0 repage \) -append new_image.png
Windows syntax:
convert image.png ( clone -gravity south -crop x1 0 0 repage ) -append new_image.png