3

I'm using the post thumbnails feature of WordPress and I have several sizes defined in functions.php. Everything's fine, it works great with Crop Thumbnail to crop them perfectly.

I have a question though regarding the automatic cropping of all images I send to the server. I wish WordPress would only create cropped versions for the images used as post thumbnails. The pictures displayed inside articles should not be cropped, since they're never used outside of the posts, and always at their full size.

Is there a way to do so ? I'd like to reduce the size of my content folder and I'm sure I could gain many bytes by disabling this automatic cropping of every pictures.

One more thing, related to this question : is there a way to delete all unused cropped images ? Over the years, I changed my theme many times and I have many old cropped versions that are unnecessary today. Is there an easy way to delete these ?

Thanks !

1

Look at this answer by Chip Bennet - Medium / Large images sizes aren't cropped by default ( and I also just verified on my install ). You can change the cropping of Thumbnails in Settings -> Media. It sounds like what you really need is just a new image size via add_image_size() which is also described in his answer.

As far as removing unused images, right now you're probably out of luck - you'll need to go backwards and remove any unused images by hand ( maybe there's a plugin out there, I'm not sure ). There a few ways to keep your WordPress clean, I prefer to delete associated media whenever a post is deleted. Charles Clarkson and t f have good answers for that. If you only want to target only the Featured Image you can look at these answers by sanchothefat and Ravs.

Really though it may be better to break you question into more specific questions to get more specific answers instead of grouping your 3 questions into one.

  • I think I don't know how to explain my problem, but I don't want to disable cropping, I just want to do it on post thumbnails only. All other pictures should be just left as they are, to save space on the server (all cropping variations are useless for these). Anyway, thanks for your answer, and sorry for the multiple questions. – nicolinux Jan 19 '15 at 21:27
  • Create a custom image size as described above. If you uncheck the thumbnail crop in Settings -> Media that will apply to all thumbnails from that point forward. – Howdy_McGee Jan 19 '15 at 21:34
  • OK, but I still want to crop the post thumbnails afterwards. But only the post thumbnails and not the other images I will send. – nicolinux Jan 19 '15 at 21:54
1

hey dude is much easy i solve your problem open functions.php file and add this code for medium crop large crop.

    if(false === get_option("medium_crop")) {
    add_option("medium_crop", "1");
} else {
    update_option("medium_crop", "1");
}

here is reference link

http://stackoverflow.com/questions/3454337/crop-thumbnail-to-exact-dimensions-on-wordpress-for-medium-size

After u apply this code regenerate all images plugin

hope solve your problem

https://wordpress.org/plugins/regenerate-thumbnails/
  • Thanks for your help, but I don't think it answers my problem. The issue is not the medium crop, but all the custom sizes I registered in my theme that are applied to all images, and not only post thumbnails. – nicolinux Jan 19 '15 at 21:53
  • @nicolinux then change your custom sizes so that the crop parameter is false – Andy Macaulay-Brook Jul 21 '16 at 11:49
  • ohh ok you want to custom size use this code add_image_size( 'about-img', 340, 150, true ); 1) true for Hard Crop 2) false for Soft Crop 3) about-img is name of the specific image section like product, portfolio etc Also the wordpress link for more detail developer.wordpress.org/reference/functions/add_image_size – Irfan Jul 27 '16 at 7:55
0

This is something that I've been working on as a core enhancement to WordPress. It's a bit of a windy road to get it done.

However, in the interim, there's a plugin approach you can take that allows you to specify the crop for any of the custom image sizes that you may have defined.

Follow this ticket: https://core.trac.wordpress.org/ticket/30062 to learn more.

This is the (hopefully temporary) demo plugin that allows the modifications necessary to core to actually save the crops for those intermediate sizes: https://core.trac.wordpress.org/attachment/ticket/21811/EnhancedImageEditorDemo_plugin.zip

And this is the demo plugin that demonstrates this ability by actually putting up a UI in the Image Editor that lets you select one of your custom image sizes and then (holding the shift key), drag a crop, constrained to the proportions of that image size.: https://core.trac.wordpress.org/attachment/ticket/21811/21811-enhanced-editor-demo.zip

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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