Page 1 of 1

Trim whitespace from top and bottom of image and distort

Posted: 2019-03-31T11:38:47-07:00
by tomchambers
What I have - image with whitespace at top and bottom
Image

What I want - image with no whitespace and content is distorted to fit space. This was done in photoshop
Image

My method for achieving this is
1. Crop image into 1x256px slices
2. Trim the whitespace/transparent pixels from top and bottom
3. Resize the image to be 1x256 so the content is stretched
4. Montage

Code: Select all

convert original.png +repage -crop 1x -trim -resize 1x256\! out.png
montage out-*.png -geometry 1x -tile x1 montage.png
Seems to be working ok, but I have a bunch of odd artefacts at regular intervals through the image. Can't work out whether this is a problem with the montaging or the cropping!

Actual imagemagick image
Image

Re: Trim whitespace from top and bottom of image and distort

Posted: 2019-03-31T11:53:27-07:00
by GeeMack
tomchambers wrote: 2019-03-31T11:38:47-07:00

Code: Select all

convert original.png +repage -crop 1x -trim -resize 1x256\! out.png
montage out-*.png -geometry 1x -tile x1 montage.png
Seems to be working ok, but I have a bunch of odd artefacts at regular intervals through the image. Can't work out whether this is a problem with the montaging or the cropping!
I don't know about artifacts. You might have to post a close up or point out a specific area that shows the problem. But I would suggest you run that as a single command. Just "+append" the cropped and resized strips like this...

Code: Select all

convert original.png +repage -crop 1x -trim -resize 1x256\! +append out.png
The result "out.png" should be your final image.

Re: Trim whitespace from top and bottom of image and distort

Posted: 2019-03-31T11:57:01-07:00
by tomchambers
The artefacts I mean are the 1px columns that appear every 20px or so and don't fit in the sequence.

But +append has solved it, thank you! I have the full image now.

Re: Trim whitespace from top and bottom of image and distort

Posted: 2019-03-31T19:02:12-07:00
by fmw42
The default separation for montage is 2 pixels so use -geometry +0+0 to make them align. But append is probably a better option.