I want to crop an image from the center in the size 200 * 130 the image to be cropped may vary in size, if the image is smaller we wont crop it i know how to this part where
Jeez, why are you doing it the hard way? Just simply set the x and y positions as the amount to crop / 2
$imageSize = getimagesize('thumbnail.png');
$croppedImage = imagecrop(imagecreatefrompng('thumbnail.png'), ['x' => 0, 'y' => ($imageSize[1]-$imageSize[0]*(9/16))/2, 'width' => $imageSize[0], 'height' => $imageSize[0]*(9/16)]);
notice how I used my $imageSize[0]*(9/16), which is the amount i am cropping by in the y direction, and i subtracted that from the original image height to find crop amount, then divided by 2. If you want to do the same for width, simply follow the same steps.