wordpress add new thumbnail size of image - wordpress

wordpress admin has 3 default image sizes i.e thumbnail,medium,large.How can i add one more type (ex:700px X 500px)so that if i upload an image it also saves in all four sizes.
Thanks in advance.

Add the following to your functions.php file.
add_image_size( 'name-of-size', 700, 500, true );
More information can be found here.
**Also note that you will need to regenerate thumbnails for those images which were previously uploaded, if you need them in the new size.

add_image_size( 'new-thumb', 110,100,true);
syntax ==> <?php add_image_size( $name, $width, $height, $crop ); ?>
Refer Here Add Image Size

Related

wp_get_attachment_image_url wordpress

I would like get an image size 640x640 and used wp_get_attachment_image_url function.
Actually, this size of image is not available in the content upload. How can I get the image which size is maximum close value 640x640?.
Basically, you can find the answer and very good example at official documentation of that function: https://developer.wordpress.org/reference/functions/wp_get_attachment_image_url/
A little summary:
add_image_size( 'image-size-640', 640, 640, true ); //resize, crop in functions.php
$img_id = 6; //need to get it dynamically
$cropped_image = wp_get_attachment_image_url( $img_id, 'image-size-640' ); //use custom set size
After you add new sizes, WordPress has to regenerate the images. Best plugin: https://wordpress.org/plugins/regenerate-thumbnails/

Add image size option

In my theme's functions.php I've added this:
function imagething () {
add_theme_support( 'post-thumbnails' );
add_image_size( 'new-custom-size', 1000, 500 );
}
add_action( 'after_setup_theme', 'imagething' );
However, when I go to media, and upload a file, I can't select the new image format.
For make the the size created with add_image_size available in the media uploader select, you need to use the filter image_size_names_choose and add your custom created size to the list of available dimensions, like this:
add_filter( 'image_size_names_choose', 'so46754923_image_size_names_choose' );
function so46754923_image_size_names_choose( $sizes ) {
return array_merge( $sizes, array(
'new-custom-size' => __( 'New Custom Size Name' ),
) );
}
Image size not showing right in the image uploader select
In case the size you chose isn't showing right in the Image Uploader Select, it may be for 2 reasons:
Content_Width set for your theme
add_image_size() crop parameter is set to false, in this case, the uploaded image may not be in the desired size.
Content width defines width for your content (images, oembed, etc...)
Example: Suppose you are using twenty seventeen theme and added a image size like you said
add_image_size( 'new-custom-size', 1000, 500, true ); //in my example I've used crop true, so the image can really be 1000 x 500, in case you don't understand about crop you have to make a research about it.
In the Twenty Seventeen the content_width is set for 525
$GLOBALS['content_width'] = 525;
And the you added the code I provided above ( so46754923_image_size_names_choose() )
You will see New Custom Size - 525 x 263
If you comment the line
$GLOBALS['content_width'] = 525;
You will see New Custom Size - 1000 x 500

picture cut offs in Wordpress/ not being fit

As you can see in the picture, when I upload my product images to WordPress the head of models cut off and I cannot see the full image in thumbnails. Does anyone have any solution for this issue ?
you can set thumnails without crop , just add custom thumnail in function.php and use it , like this :
in function.php ::
add_action( 'after_setup_theme', 'wpdocs_theme_setup' );
function wpdocs_theme_setup() {
add_image_size( 'my-thumb', 50 ); // 50 pixels wide by 50 pixels tall, resize mode (whitout croped)
}

Wordpress: get resized URL of the custom-cropped thumbnail

I would like to display the manually-cropped thumbnail in the blog archive page. If I use this code, the original image is scaled and resized and not the manually cropped/sized thumbnail, which in my case chops off the head of the person in the picture:
//functions.php
add_image_size( 'archive-thumbnail', 220, 150, true );
set_post_thumbnail_size( 220, 150 );
//archive.php
get_the_post_thumbnail( get_the_ID(),'archive-thumbnail');
If I use the_post_thumbnail(array(220,150)); , I get 150px high "square-ish" image scaled down, again, based on the original image and not the manually-cropped thumbnail.
The closest to what I want is this:
$url=wp_get_attachment_thumb_url(get_post_thumbnail_id(get_the_ID()));
I get the manually cropped image, but it is scaled incorrectly - it is 150px wide and not tall.
So my question: how do I get the scaled URL of the manually cropped media thumbnail?
You want to use wp_get_attachment_image_src() to get the resized image - the functionwp_get_attachment_thumb_url() is a shortcut to get the thumbnail size.
$post_id = get_the_ID();
$thumb_id = get_post_thumbnail_id( $post_id );
$img_src = wp_get_attachment_image_src( $thumb_id, 'archive-thumbnail' );
If you edit code related to thumbnails after thumbnails have already been created, you need to regenerate them. Try using the Regenerate Thumbnails plugin.

wordpress - get thumbnail size from thumbnail name/reference

I have set up a thumbnail like
add_image_size( 'banner_image', 1098, 400, true );
now after this is registered I want to be able to get the dimensions from the reference, i.e.
get_thumbnail_size( 'banner_image' )
{
}
is there anyway of doing this?
regards
global $_wp_additional_image_sizes;
echo $_wp_additional_image_sizes['banner_image']['width']; // output width
echo $_wp_additional_image_sizes['banner_image']['height']; // output height

Resources