How to crop 32 pixels at the top?

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
bensto
Posts: 31
Joined: 2012-07-02T00:32:10-07:00
Authentication code: 13

How to crop 32 pixels at the top?

Post by bensto »

As far as I know I can crop a picture to a height of 3000 pixels by the following command:

convert in.jpg -crop x9000+0+0 +repage out.jpg

However the cropped part is here always at the bottom of the picture.

How can I tell ImageMagick to only crop at the top of the picture?

How can I tell Imagemagick to crop 32pixels at the top regardless of how height the picture is in total?

How can I specify to crop 22 pixels at the top and 10 pixels at the bottom?

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

Re: How to crop 32 pixels at the top?

Post by snibgo »

bensto wrote:As far as I know I can crop a picture to a height of 3000 pixels by the following command:

convert in.jpg -crop x9000+0+0 +repage out.jpg
No. If you want a height of 3000 pixels, ask for 3000, not 9000.

Precede with "-gravity" if you want, eg "-gravity North" to get rows from the top of the image, or South to get rows from the bottom.

To remove a certain number from the top or bottom, use "-gravity XX -chop". See http://www.imagemagick.org/script/comma ... s.php#chop
snibgo's IM pages: im.snibgo.com
bensto
Posts: 31
Joined: 2012-07-02T00:32:10-07:00
Authentication code: 13

Re: How to crop 32 pixels at the top?

Post by bensto »

Thank you.

Is the chop operation lossless?

After applying

convert.exe test.jpg -gravity North -chop x160 +repage out.jpg

in the resulting picture the heaven seems to be much more blue than in the original.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to crop 32 pixels at the top?

Post by fmw42 »

Chop is lossless. The issue is that you are using jpg images. They are lossy compressed. So your image must be decompressed, chopped and recompressed and this will not be lossless.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to crop 32 pixels at the top?

Post by snibgo »

"-chop" removes pixels. It doesn't change pixels.

Writing to JPEG is lossy. Pixels will change. But I doubt that "seems to be much more blue" comes from that. That's more likely to be an illusion.
snibgo's IM pages: im.snibgo.com
bensto
Posts: 31
Joined: 2012-07-02T00:32:10-07:00
Authentication code: 13

Re: How to crop 32 pixels at the top?

Post by bensto »

Thank you for clarification.

However after ImageMagick decompressed (internally) the *.jpg and applied the -chop command a re-compression takes place:

At which compression level (by default)?

Assume I want a compression level of 97%: How can I specify this in the convert command above?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to crop 32 pixels at the top?

Post by snibgo »

JPEG compression is controlled by "-quality". See http://www.imagemagick.org/script/comma ... hp#quality . This is a number from 1 to 100, but not a percentage.
snibgo's IM pages: im.snibgo.com
bensto
Posts: 31
Joined: 2012-07-02T00:32:10-07:00
Authentication code: 13

Re: How to crop 32 pixels at the top?

Post by bensto »

ok. Thx
Post Reply