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

How to crop 32 pixels at the top?

Post by bensto » 2017-10-02T22:17:19-07:00

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: 9404
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 » 2017-10-02T22:37:30-07:00

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

Re: How to crop 32 pixels at the top?

Post by bensto » 2017-10-03T09:51:31-07:00

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: 22109
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: How to crop 32 pixels at the top?

Post by fmw42 » 2017-10-03T09:54:58-07:00

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: 9404
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 » 2017-10-03T09:57:39-07:00

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

Re: How to crop 32 pixels at the top?

Post by bensto » 2017-10-06T06:20:28-07:00

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: 9404
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 » 2017-10-06T06:30:04-07:00

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

Re: How to crop 32 pixels at the top?

Post by bensto » 2017-10-06T06:37:37-07:00

ok. Thx

Post Reply