Having a problem in the wordpress images when cropping doesn’t follow in your way. This tutorial will help you how can you crop images using functionality code build in to wordpress.

Final Code

$post_thumbnail_id = get_post_thumbnail_id( get_the_ID() );
$attachment = get_post( $post_thumbnail_id );
$imageURI = $attachment->guid;

$path = get_attached_file( $attachment->ID );
$filename = basename ( get_attached_file( $attachment->ID ) );
$path = str_replace($filename, "", $path); 

$image_size = '800x533';
$img_temp = explode("x", $image_size);
$img_width = $img_temp[0]; 
$img_height = $img_temp[1]; 

$filename_explode = explode(".", $filename);
$filename_name = $filename_explode[0];
$filename_ext = $filename_explode[1];
$exist = $path . $filename_name.'-'.$image_size.'.'.$filename_ext;

if(!file_exists($exist)):
   $img_path = $path;
   $img_name = $filename;
   $image = wp_get_image_editor( $img_path . $img_name );
   if ( ! is_wp_error( $image ) ) {
      $image->resize( $img_width, $img_height, true );
      $image->save( $img_path . $image_size.'-'-$filename );
   }
endif;
var_dump($final_image);

Let me explain the code so we can easily know what all the purpose of this final code

$post_thumbnail_id = get_post_thumbnail_id( any post ID HERE );
$attachment = get_post( $post_thumbnail_id );
$imageURI = $attachment->guid;

$path = get_attached_file( $attachment->ID );
$filename = basename ( get_attached_file( $attachment->ID ) );
$path = str_replace($filename, "", $path);

This code is to get the absolute path of the images you want to re-crop make sure you have the right post ID more info for get_attached_file.

$image_size = '800x533';
$img_temp = explode("x", $image_size);
$img_width = $img_temp[0]; 
$img_height = $img_temp[1];

$image_size is the code you want a specific size for your images to be crop then I just explode it to be able to input in the crop images area $image->resize( $img_width, $img_height, true );

$filename_explode = explode(".", $filename);
$filename_name = $filename_explode[0];
$filename_ext = $filename_explode[1];
$exist = $path . $filename_name.'-'.$image_size.'.'.$filename_ext;

This code is just to specify if the path is exist you will not need to re-crop that images so it will not cause any duplication.

if(!file_exists($exist)):
   $img_path = $path;
   $img_name = $filename;
   $image = wp_get_image_editor( $img_path . $img_name );
   if ( ! is_wp_error( $image ) ) {
      $image->resize( $img_width, $img_height, true );
      $image->save( $img_path . $image_size.'-'-$filename );
   }
endif;

$imageURI_temp = str_replace($filename, "", $imageURI);
$final_image = $imageURI_temp . $filename_name .'-'.$image_size.'.'.$filename_ext;
var_dump($final_image);

This code where the images crop involve as you can use this wp_get_image_editor as build in wordpress functionality to crop any images that you want then save it to a specific path. Now it was save then do a passing variable condition and output it into the $final_image. This $final_image variable contain the new url link image that you can pass to the img tags.

You can use this code when generating some images you want to crop specially in masonry grid or blog post that you want to be a same size product thumbnails and etc. Hope will help you overcome some  good way and controllable wordpress images crop. Consider this a part of Techniques for Web development.