Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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!!

share|improve this question

4 Answers 4

up vote 10 down vote accepted

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 a image_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().

add_filter('wp_generate_attachment_metadata', 'custom_crop');

function custom_crop($metadata) {

    $uploads = wp_upload_dir();
    $file = path_join( $uploads['basedir'], $metadata['file'] ); // original image file
    list( $year, $month ) = explode( '/', $metadata['file'] );
    $target = path_join( $uploads['basedir'], "{$year}/{$month}/".$metadata['sizes']['medium']['file'] ); // intermediate size file
    $image = imagecreatefromjpeg($file); // original image resource
    $image_target = wp_imagecreatetruecolor( 44, 44 ); // blank image to fill
    imagecopyresampled($image_target, $image, 0, 0, 25, 15, 44, 44, 170, 170); // crop original
    imagejpeg($image_target, $target, apply_filters( 'jpeg_quality', 90, 'image_resize' )); // write cropped to file

    return $metadata;
share|improve this answer
sounds a lot like messing with the core!! –  Mild Fuzz Jun 24 '11 at 9:35
No, messing with the core would be changing the image_resize function. Rarst was making the point that you'd have to hook into the resizing process, but create the image sizes yourself manually. –  TheDeadMedic Jun 24 '11 at 10:02
May I ask if this still works? I just implemented the hook into my functions.php file and I have add_image_size() functions set-up, but the cropped images still get cropped form the center out. –  cr0z3r Dec 9 '11 at 22:40
@cr0z3r I know of no reason why it won't work. But note that this is only rough proof-of-concept example, rather than meaningful reliable code. –  Rarst Dec 10 '11 at 13:50
Hm, strangely enough, it does not work on my theme - could it be because I was running locally (I highly doubt it)? I will have it up online and show it to you soon. –  cr0z3r Dec 15 '11 at 16:32

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.

share|improve this answer
@Rarst’s solution doesn’t change core files too. ;) –  toscho Feb 19 '12 at 15:25
@toscho I guess he didn't mean that the other answer changes core code. –  kaiser Feb 20 '12 at 15:16

You can use the plugin Thumbnail Crop Position to select the crop position of your thumbnails.

share|improve this answer

Wordpress codex has the answer, its below.

Set the image size by cropping the image and defining a crop position:

add_image_size( 'custom-size', 220, 220, array( 'left', 'top' ) ); // Hard crop left top

When setting a crop position, the first value in the array is the x axis crop position, the second is the y axis crop position.

x_crop_position accepts 'left' 'center', or 'right'. y_crop_position accepts 'top', 'center', or 'bottom'. By default, these values default to 'center' when using hard crop mode.

And also codex references a page which shows how crop positions acts.


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.