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:
And when I check in the directory it crop automatically into these sizes:
How this thing is happening?
WordPress by default is designed to generate 3 types of cropping of any uploaded images (Media):
It’s to ensure site speed with different sizes where necessary. So, with uploading the Original image there would be at least 4 files-
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 still 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 yourfunctions.php
to add your desired image size: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 writetrue
if you want to hard-crop the image, otherwise usefalse
Typically we can call different Featured Image into any place of our theme by using:
If you want to use your new size, use:
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:
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’sfunctions.php
or any added functions file for suchadd_image_size()
function, and now you know what to do.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 theglobal $_wp_additiona_image_sizes
to store & handle the settings for your image generation. Now, when you upload an image, the classWP_Image_Editor
comes into game and – depending on the PHP extensions enabled on your server – either callsWP_Image_Editor_GD
orWP_Image_Editor_Imagick
. Now both Singletons have aresize()
method which callsimage_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 nativeimagecopyresampled()
inside the GD class.How to disable cropping?
First, we have lots of possibilities:
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.
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 fromnull
, 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 asimage_resize_dimensions()
uses per default. From the inline comments: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.
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.
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:
For example, like this:
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.
Plugins and Themes can define their own thumbnail sizes. WordPress will convert all newly uploaded images to all registered size definitions.
To disable cropping, insert this below code in
disable-automatic-image-crop.php
file in your mu-plugins folder: