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.

Am new to WordPress, when I upload any image, WordPress automatic crops into its own sizes which I have not mention in the media section (Settings » Media).

Settings which I saved in media is:
Setting which i saved in media.

And when I check in the directory it crop automatically into these sizes:
enter image description here

How this thing is happening?

share|improve this question
2  
One thing to note @Abhishek360, is even if you disable all plugins/themes, all photos that were previously cropped/created will remain there, unless you use the plugin Regenerate Thumbnails. Using this plugin should delete/add any image sizes for all images. :) Link here: wordpress.org/plugins/regenerate-thumbnails –  Eric Holmes Nov 21 '13 at 14:06
    
thanks i will definitely give a try to that plugin –  abhishek360 Nov 22 '13 at 5:24

4 Answers 4

up vote 4 down vote accepted

WordPress by default is designed to generate 3 types of cropping of any uploaded images (Media):

  • Thumbnail (Typically 150px x 150px)
  • Medium (Typically 300px x 300px)
  • Large (Typically 1024px x 1024px)

It's to ensure site speed with different sizes where necessary. So, with uploading the Original image there would be at least 4 files-

  1. The Original File (not-cropped),
  2. Large,
  3. Medium, and
  4. Thumbnail.

As you already know that, from /wp-admin/options-media.php, you can change the default size's dimensions too. So you can still use the default sizes for your custom purpose. but if you till need a new size other than the three, WordPress allows you to add new image sizes too.

Using add_image_size() function with your desired parameter allows you to add new size for your site. Use the function into your functions.php to add your desired image size:

add_image_size( $name, $width, $height, $crop );

Where —
$name : string write the name within single quote, i.e. 'portfolio'
$width: integer write the width you want, i.e. 500 (in px)
$height: integet write the height you want, i.e. 300 (in px)
$crop: boolean write true if you want to hard-crop the image, otherwise use false

Typically we can call different Featured Image into any place of our theme by using:

the_post_thumbnail( 'medium' ); //it will display only the medium size of the original image

If you want to use your new size, use:

the_post_thumbnail( 'portfolio' ); //as I named my size as 'portfolio'

WARNING: As, by default WordPress is generating 3 customizable image sizes, it's creating 4 files for each images. Using more new sizes will increase the number of files into your site host. So, using more image sizes will be a matter for your site's host-space issue— it'll consume more site spaces.

EDIT

And after adding every new image size, a most important plugin is:

» Regenerate Thumbnail — WordPress Plugin

In reality the newly assigned image size can be available only into newly uploaded images. So, to get the new size for all the previously uploaded images too, you will need the plugin to be installed and regenerate all the thumbnails again. It'd be one-time measure that would last forever*.

And your main answer should be:
Site Speed: WordPress crops images to increase site speed. If you use Google PageSpeed, you'll be known that it suggests:

Serve scaled images
Properly sizing images can save many bytes of data.
Learn More

EDIT 2

As you are already suggested, if your plugin use a similar add_image_size() function, it can create a new image size. So after disabling your plugins, if you use the Regenerate Thumbnails plugin to regenerate the thumbnails, then you will get the actual sizes. If that doesn't help, then check your theme's functions.php or any added functions file for such add_image_size() function, and now you know what to do.

share|improve this answer
    
Please check the two edits also –  Mayeenul Islam Nov 21 '13 at 15:07
    
Detailed and good answer +1 –  kaiser Nov 22 '13 at 6:19
    
You saved me so much time, thanks so much for this details explanation ! –  Julien Sep 29 at 12:31

Yes, WordPress resizes & crops all images depending on what your theme defined as @Gerard already explained in his answer. So the last boolean argument for add_image_size() is to crop or not. Note that this doesn't define the crop position. To alter that behavior look at this answer for example.

What happens inside core?

As you've already seen in the source of add_image_size(), WP uses the global $_wp_additiona_image_sizes to store & handle the settings for your image generation. Now, when you upload an image, the class WP_Image_Editor comes into game and - depending on the PHP extensions enabled on your server - either calls WP_Image_Editor_GD or WP_Image_Editor_Imagick. Now both Singletons have a resize() method which calls image_resize_dimensions(). At the end, image_resize_dimensions() does not resize or crop the image. It just calculates the values.

This is done by the method crop() in the Imagick class and by using PHPs native imagecopyresampled() inside the GD class.

How to disable cropping?

First, we have lots of possibilities:

  • detect which class is in use (which PHP ext. is supported) and then intercept whatever is used to crop (see above).
  • Short circuit the whole process and let image_resize_dimensions() do it's work.

We'll use the later method in here. Feel free to add your own solution as separate answer. Here's what core offers us: A filter holding all parameters.

$output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop ); 

Now the first argument is null, which tells core on the next line if we want to overwrite what this function does internally - and replace it with our own behavior - or not. So if we'd return anything aside from null, then this is what core will use. Keep in mind that you can put anything there, but still core will expect the same return value as image_resize_dimensions() uses per default. From the inline comments:

The return array matches the parameters to imagecopyresampled():

int dst_x, int dst_y,

int src_x, int src_y,

int dst_w, int dst_h,

int src_w, int src_h

Now to just disable crop we'd have to replace (in other words: clone) the whole internals - something that we want to avoid. Therefore we're using a "one time filter" that disables itself. We're doing that to use the internals, but just get rid of what we don't need.

<?php
defined( 'ABSPATH' ) or exit;
/* Plugin Name: (#124009) Disable image crop */

add_filter( 'image_resize_dimensions', 'wpse124009DisableCrop', 10, 6 );
function wpse124009DisableCrop( $enable, $orig_w, $orig_h, $dest_w, $dest_h, $crop )
{
    // Instantly disable this filter after the first run
    remove_filter( current_filter(), __FUNCTION__ );

    return image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, false );
}

Now cropping is disabled everywhere. If you're running multisite or you don't want to think about if this plugin is enabled, simply go and use it as a mu-plugin.

Please keep in mind that above is not tested, but written off of my head after reading core source.

Additional info

More info about the image handling classes in the slides of Marko from WordCamp Europe and the video of the presentation can be found on WordPress.tv.

share|improve this answer
2  
kaiser,who taught you such stuff who is your tutor.I want to become your devoted student.:) –  abhishek360 Nov 22 '13 at 5:35
    
@abhishek360 I already am one. :) –  Mayeenul Islam Nov 22 '13 at 6:47
    
@MayeenulIslam seriously you are one of his student i also want to become ninja in wp. If kaiser(grand master) is bussy will you accept me as a student. –  abhishek360 Nov 22 '13 at 6:57
1  
@abhishek360 Opps! ;) Here in this platform, everybody is everybody's student, or teacher. We all are trying to learn something from within. Nobody can taught, but learning comes within. Be with this platform, serve other, practice more, there are many like Kaiser, who are our teachers. I'm still a baby in WP - and they are my mentors. ;) –  Mayeenul Islam Nov 22 '13 at 8:14
    
@MayeenulIslam awesome words..if you are baby in wp then i guess i have not yet born anyways i will explore more..thanks –  abhishek360 Nov 22 '13 at 9:33

Plugins and Themes can define their own thumbnail sizes. WordPress will convert all newly uploaded images to all registered size definitions.

share|improve this answer
    
I have disabled all plugin except (akismet)and am using theme twenty thirteen.So can you assist me more.what i do so that it crop only my defined size. –  abhishek360 Nov 21 '13 at 13:35
    
@abhishek360 when u say u have disabled all the plugin and using a base theme like 2013. Can you try and upload a new image and see if you still have different images? –  Maruti Mohanty Nov 21 '13 at 14:01

Normally it is because a Wordpress theme uses the thumbnails on its code: in loops, galleries, etc. It is defined in the file functions.php:

add_image_size( $name, $width, $height, $crop );

For example, like this:

add_theme_support('post-thumbnails');
add_image_size('custom-thumbnail', 80, 80, true );
add_image_size('medium-thumbnail', 180, 120, true );
add_image_size('large-thumbnail', 571, 300, true );

I don't recommend you to remove the code if you really want to keep the good working of your theme. If you want to remove it, you will need to delete the calls in the other files where it is used; commonly in the file loop.php.

share|improve this answer
    
so if i remove the calls from loop,galleries pages then it would take only my defined size? wiht out affecting my theme is it possible. –  abhishek360 Nov 21 '13 at 13:51
    
Yes, it is. The defined size from your first screenshot will be used when you want to insert an image in a post. The other sizes defined in functions.php are used as thumbnails/images for the theme structure, so it's highly probable you will need to arrange the CSS also. –  Gerard Nov 21 '13 at 13:58
    
ohh am not that much technical guy who can edit where ever he like.Can you suggest me what should i do to achieve that easily and the code which you have pasted above such thing was not there in my function.php i have pasted all that and defined the size.hope that works. –  abhishek360 Nov 21 '13 at 14:09
    
Well, if it is not into functions.php, it is because that file has 'includes' or 'requires' of other files, separeting its content in several files. You need to look the other files in order to delete the function containing add_image_size. If you added the code I pasted before, your theme will make more crops than before. PS: Btw, most of the themes generate crops like this one, and it's only a problem if you need to optimize the memory of the server. If you need it, the images cropped are saved into the 'Uploads' directory. Could you paste the functions.php on Pastebin? I'll take a look :) –  Gerard Nov 21 '13 at 14:48
1  
thanks Gerard, Mayeenul Islam and kaiser solved my problem i want only definite set of crop image of definite size and i achieved that. –  abhishek360 Nov 22 '13 at 5:43

Your Answer

 
discard

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.