How wordpress handle upload images and how to use them in the code

WordPress crops the image proportional to the uploaded images dimensions, unless for the thumbnail size you specify to crop the thumbnail ( option provided only for thumbnails ). Hence the images being created are renamed to the size they are being cropped to.

By default WordPress creates 4 images or less depending on the size of image you upload. One would be the original image, large, medium, thumbnail. Incase the uploaded image is smaller than the size mentioned for thumbnail, then no extra image would be created. More images size can be created when an images is uploaded by using this function.

$crop = true; //if you want the image to stay proportional set this to false
add_image_size( 'extra', 135, 135, $crop);

Coming to how you can use the different sizes, they can be used using the following codes in a Loop.

the_post_thumbnail( 'thumbnail' );
the_post_thumbnail( 'medium' );
the_post_thumbnail( 'large' );
the_post_thumbnail( 'full' ); //this will output the whole image as was uploaded
the_post_thumbnail( 'extra' ); //if using the above add_image_size code.

Leave a Comment