Adding a custom image size to WordPress could not be easier. The following will create a size called Square that is 150 by 150 pixels, the parameter true will result in the cropping of an image.
add_image_size('square', 150, 150, true);
Now any time an new image is uploaded WordPress will generate a file something like image-150×150.jpg.
If you want to be able to insert these images in your posts then you will need to register the size with the Media moda.
add_filter('image_size_names_choose', 'add_image_sizes_editor');
function add_image_sizes_editor($sizes)
{
return array_merge($sizes, [
'square' => __('Square', 'axe'),
]);
}
Now when you create a post and want to add an image your custom sizes will be available to you.