Crop and Resize images in WordPress: how to change cropping origin?

Ok, let’s recall how WordPress currently (version 3.8 as I write) does manage images, cropping and resizing.

Some basic knowledge of the image workflow in WordPress:

Images in WordPress are truly posts of the type “Image”. These posts can be attached to a content post or can be independent. It will depend if you attach it from the Media screen or you attach it from the Edit Post/New Post screen.

Everytime you upload an image, the subsequent resized images are immediately created. They will have the sizes determined as standard: the defaults are explained here https://codex.wordpress.org/Function_Reference/the_post_thumbnail. These are thumbnail, medium, large, 150×150, 300×300 and 640×640, plus the full size.

It is funny that WP maintains the naming “thumbnail” for all of them, this is a bit confusing as a naming. Probably has to do with legacy code…

Post thumbnail is also the naming used for “featured image”.

Things you can do with thumbnails:
– You can resize the existing types. You can do that already from the admin menu, but you can also use the function
– You can create new image sizes

The problem comes when you create new image sizes, because if they do not have the aspect-ratio of the thumbnails, they will have to be cropped as well as resized.

What I mean is that, if you have an image 800×600 (4:3) and resize it to 800×300, then the image will be cropped at the center. But maybe you want to have it cropped from the top.

The standard is center,center for x,y. But other options should be given.

As Brad Touesnard proposes with this patch to the WordPress core http://bradt.ca/blog/image-crop-position-in-wordpress/. This patch is currently under discussion, two years after it was proposed by Bradt https://core.trac.wordpress.org/ticket/19393.

I believe that such change is needed in WordPress core, because it will allow to have other cropping options, for example cropping from the top instead of the middle in the y-axis. This is useful for many situations where you have a header/title in the image, or the head of a person. These types of images would look really bad if the head or title is cut by the middle.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s