how to copy a rectangle region from an image file? (“cropping”)

My original source files are PDF files, but I already converted them to PNG using Ghostscript.

I was thinking of ImageMagick

I came across phatch, I read of it here. It’s a GUI, that helps running ImageMagick with certain operations in a batch. It came with a lot of dependencies on other packages. I tried to fullfil some of of them, eventually I gave up. If I very sure, that phatch was the way to go, that dependency hell wouldn’t be a dead end. Spending time on getting phatch to run was a dead end for me.

There is a book on ImageMagick at PackPub, there is also one at Apress. I bought both of them as PDFs. That was the key to the success. I found nice examples, and I was able to apply some easy recipe to my task.

$ convert orig.png -crop geometry new.png

Actually the recommendation says to use “+repage“, in order to not confuse certain software:
$ convert orig.png -crop geometry +repage new.png
Without “+repage” the file stores the displacement of the segment wrt. the original image, which comes in quite handy, but … certain software gets confused, eg. when I loaded one such new image into GIMP, GIMP displayed the displacement and presented me rubbish.

There is a fork of ImageMagick called GraphicsMagick. Pretty fast, but you may come across features of ImageMagick, that GraphicsMagick doesn’t know.


Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.