I want to modify wordpress's core files to get a desired result for cropping and saving uploaded images. However, i can't find the function that handles the uploaded images and crops, renames and saves them.

I thought this function may have something to do with thumbnails :wp_generate_attachment_metadata

Can anyone help me which file and function does this? Thank you

  • 4
    I would note the function that does this will be very expensive to run, you'll want to use add_image_size if you need to size images for your theme, and you'll want to do any cropping calls on the admin side, never on the frontend, else you could get pages that take minutes to load in the worst scenario
    – Tom J Nowell
    Oct 20, 2016 at 20:44

2 Answers 2


The image goes through multiple processes for the thumbnail to be generated. Take a look into the WP_Image_Editor class in the wp-includes/class-wp-image-editor.php.

This class handles cropping, resizing, etc.

There is a public function inside this class, named crop(). This might be what you are after. However, the actual resizing is handled by the function multi_resize(), which generates thumbnails for each uploaded image.


Looks to me like it's wp_crop_image & wp_ajax_crop_image

  • Thank you. do there functions do the thumbnail generation? or they do the manual crop in the admin-side image edit page? i want the 1st one.
    – Johansson
    Oct 21, 2016 at 1:04
  • I've noticed that image_downsize does the thumbnail generation. @TomJNowell no, i wanted to modify wordpress's core to have completely custom thumbnail name, and directory structure.
    – Johansson
    Oct 21, 2016 at 19:25
  • Ah, you'd want to filter it, modifying core code directly is a terrible thing to do that opens up all sorts of difficult problems, such as them all being overwritten when you update
    – Tom J Nowell
    Oct 24, 2016 at 11:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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