Cutting x pixels from an image

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
adamsilver
Posts: 3
Joined: 2013-03-24T20:49:57-07:00
Authentication code: 6789

Cutting x pixels from an image

Post by adamsilver »

Why this is creating many images instead of just two?

Code: Select all

convert input-image.jpg -crop 28x +repage monet_vertical_%d.jpg
I want to get two images; 28 pixels from the base and another image with what's left.

Please help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Cutting x pixels from an image

Post by fmw42 »

It is doing tile cropping and the part you specified is not half of the image.

Because you are doing tile cropping and you have specified only a small part of the image. It will try to crop out every section that is 28 pixels by full height.

I do not think you can do unequal tile cropping to get only two sections.

To get only two sections, you must split in half, so you can do -crop 50%x100%+0+0 and get two halves.

But you cannot do -crop 25%x100%+0+0 unless you want 4 parts.

To do what you want, you need to do two separate one section crops.

convert image -crop 28x+0+0 +repage output1
convert image -crop WWx+0+0 +repage output2

where WW=W-28

see
http://www.imagemagick.org/Usage/crop/#crop_tile

and the whole section about cropping at
http://www.imagemagick.org/Usage/crop/#crop
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Cutting x pixels from an image

Post by anthony »

you can also use -chop to get the second half of the image.

Code: Select all

convert image -crop 28x0+0+0 +repage output1
convert image -chop 28x0+0+0  output2
or use an alternative -chop using -crop technique
See Chop, removing rows, columns and edges
http://www.imagemagick.org/Usage/crop/#chop

Code: Select all

convert image -crop 28x+0+0 +repage output1
convert image -crop 0x0+28+0 +repage output2
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
adamsilver
Posts: 3
Joined: 2013-03-24T20:49:57-07:00
Authentication code: 6789

Re: Cutting x pixels from an image

Post by adamsilver »

Thank you guys. Anthony's first method worked for me.

Code: Select all

	convert $f -gravity South  -crop 0x28+0+0 +repage label.jpg
	convert $f -gravity South  -chop  0x28  not-labeled.jpg
Post Reply