Positioning the crop area in add_image_size

I cannot count how many times I used add_image_size to register custom image sizes in WordPress, but I never realized that instead of true/false you can also set the crop area by using an array in the fourth parameter.

add_image_size( 'image-size-name', 250, 250, array( 'center', 'center' ) );Code language: PHP (php)

Any of the following keyword combinations:

  • left / top
  • left / center
  • left / bottom
  • right / top
  • right / center
  • right / bottom
  • center / top
  • center / center
  • center / bottom

Developer Handbook – add_image_size

Made with ❤️ in Switzerland