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
This might help you.
function cropCentered($img, $w, $h)
{
$cx = $img->getWidth() / 2;
$cy = $img->getHeight() / 2;
$x = $cx - $w / 2;
$y = $cy - $h / 2;
if ($x < 0) $x = 0;
if ($y < 0) $y = 0;
return $img->crop($x, $y, $w, $h);
}
I'm assuming you're using the GD library. $img is a GD image, $w and $h are width and height, respectively, you want your new image to have. In your case, $w = 200, $h = 130.