PHP
(quick guide & examples)
ORIGINAL IMAGE $img = imagecreatefromwebp(IMG.WEBP");
CROP 500 X 300 FROM TOP LEFT CORNER $crop = imagecrop($img, [ "x" => 0, "y" => 0, "width" => 500, "height" => 300 ]); imagewebp($crop, "demo-A.webp");
ORIGINAL IMAGE $i = imagecreatefromwebp(IMG.WEBP"); $swidth = imagesx($img); $sheight = imagesy($img);
CROP AREA DIMENSIONS (50%) $tocrop = 0.5; $cwidth = ceil($swidth * $tocrop); $cheight = ceil($sheight * $tocrop);
CROP COORDINATES (FROM CENTER) $sx = ceil(($swidth / 2) - ($cwidth / 2)); $sy = ceil(($sheight / 2) - ($cheight / 2)); $area = [ "x" => $sx, "y" => $sy, "width" => $cwidth, "height" => $cheight ];
CROP IMAGE $crop = imagecrop($img, $area); imagewebp($crop, "demo-B.webp");