I have a series of posts, all with featured images, but I need to be able to customise the crop top right corner. In this instance, I need them to be cropped from top right, but it would be useful to also know how to position that point myself.
At present, the add_image_size() function is taking its crop from the centre of the image. Not always pretty!!
Intermediate image generation is extremely rigid.
image_resize()
keeps it close to code and completely lacks hooks.Pretty much only option for this is to hook into
wp_generate_attachment_metadata
and overwrite WP-generated image with your own (which will need bit of aimage_resize()
fork).I need this for work so I might be able to share some code later.
Ok, here is rough, but working example. Note that setting up crop in this way requires understanding of
imagecopyresampled()
.WordPress codex has the answer, its below.
And also codex references a page which shows how crop positions acts.
I have developed a solution to this problem that does not require hacking the core: http://bradt.ca/archives/image-crop-position-in-wordpress/
I have also submitted a patch to core:
http://core.trac.wordpress.org/ticket/19393
Add yourself as a Cc on the ticket to show your support for it to be added to core.
You can use the plugin Thumbnail Crop Position to select the crop position of your thumbnails.
Alternative solution here: http://pixert.com/blog/cropping-post-featured-thumbnails-from-top-instead-of-center-in-wordpress-with-native-cropping-tool/
Just add this code to functions.php, then use “Regenerate Thumbnails” plugin (https://wordpress.org/plugins/regenerate-thumbnails/):