crop

crop pixels by defining a selection box

$ pierogis crop ./input.jpg -x 20 --height 400 --aspect 1 --origin c
cropped gnome

very chill.

The interface for cropping is based on defining a rectangular area to select out of the image.

--width and --height will correspond to percentages of input width if they are decimals (.5 meaning: spanning half of the input width). 1 does not mean 100% of the pixels, leave out height/width to do that!

You can provide -x and -y to define an offset from the origin at which the rectangle is pegged. x=0, y=0 corresponds to the bottom left of the image.

-x and -y will also correspond to percentages if they are decimals (.5 meaning: halfway offset from origin to end of the image in that axis).

You can provide a direction that will define the origin and the direction of the selection

origins

  • sw bottom left (default) -> top right

  • se bottom right -> top left

  • nw top left -> bottom right

  • ne top right -> bottom left

  • n top center -> bottom center

  • s bottom center -> top center

  • e center right -> center left

  • w center left -> center right

  • c center center -> outwards

--aspect will crop the image to the given aspect ratio. It achieves this in different ways depending on the other options provided.

  • If neither --width nor --height are provided, it will preserve one dimension and reduce another so as to not increase in size. Same treatment as resize.

  • If both --width and --height are provided, the --aspect is ignored.

  • If one of --width or --height are provided, the --aspect is applied to the missing dimension.

Pixel coordinates within the rectangle but without the input image will be ignored.

arg

description

default

valid

--origin

origin location and opposing direction to crop toward

sw

see origins

-x

x origin offset; decimal for relative to input width

0

float, int

-y

x origin offset; decimal for relative to input height

0

float, int

--width

width to capture; decimal for relative to input width

None

float, int

--height

width to capture; decimal for relative to input height

None

float, int

--aspect

aspect ratio; ignored if height and width present

None

float

The following table explains the x,y coordinates (the last 4 columns) of the cropped output’s bottom left and top right corners for each set of inputs.

0,0 corresponds to the left,bottom of an image and a larger x,y coordinate indicates toward the right,top of the image. If you are reading this you are a champion.

Crop Examples

x

y

width

height

origin

aspect

bottom left x

bottom left y

top right x

top right y

0

0

None

None

None

None

0

0

500

500

0

0

100

100

None

None

0

0

100

100

0

0

100

100

sw

None

0

0

100

100

0

0

100

100

se

None

400

0

500

100

0

0

100

100

nw

None

0

400

100

500

0

0

100

100

ne

None

400

400

500

500

0

0

100

100

c

None

200

200

300

300

0

0

100

100

n

None

200

400

300

500

0

0

100

100

e

None

400

200

500

300

0

0

100

100

s

None

200

0

300

100

0

0

100

100

w

None

0

200

100

300

0

0

100

None

sw

None

0

0

100

500

0

0

None

100

sw

None

0

0

500

100

100

0

100

None

sw

None

100

0

200

500

0

100

100

None

sw

None

0

100

100

500

100

0

100

None

nw

None

100

0

200

500

-100

0

100

None

ne

None

300

0

400

500

-0.2

0.2

100

None

se

None

300

100

400

500

-100

0

100

None

c

None

100

0

200

500

0.2

0

100

None

c

None

300

0

400

500

0

0.2

100

None

c

None

200

100

300

500

0

0

None

None

sw

2

0

0

500

250

0

0

None

None

ne

0.5

250

0

500

500

0

0

None

200

sw

2

0

0

400

200

0

100

None

200

c

0.5

200

250

300

450

0

0

100

None

n

2

200

450

300

500

0

0

100

100

e

2

400

200

500

300

See: CropFilling, Crop