function process_form()
 {
     $x1 = required_param('x1', PARAM_INT);
     $y1 = required_param('y1', PARAM_INT);
     $x2 = required_param('x2', PARAM_INT);
     $y2 = required_param('y2', PARAM_INT);
     $width = $x2 - $x1;
     $height = $y2 - $y1;
     $info = lightboxgallery_image_info($this->imagepath);
     if ($width > 0 && $height > 0) {
         if ($image = lightboxgallery_imagecreatefromtype($info->imagesize[2], $this->imagepath)) {
             $cropped = lightboxgallery_image_create($width, $height);
             imagecopybicubic($cropped, $image, 0, 0, $x1, $y1, $width, $height, $width, $height);
             $this->save_image_resource($cropped, $info->imagesize[2]);
         }
     }
 }
function lightboxgallery_resize_image($image, $infoobj, $width, $height, $offsetx = 0, $offsety = 0)
{
    global $CFG;
    $resized = lightboxgallery_image_create($width, $height);
    $oldwidth = $infoobj->imagesize[0];
    $oldheight = $infoobj->imagesize[1];
    $cx = $oldwidth / 2;
    $cy = $oldheight / 2;
    $ratiow = $width / $oldwidth;
    $ratioh = $height / $oldheight;
    if ($ratiow < $ratioh) {
        $srcw = floor($width / $ratioh);
        $srch = $oldheight;
        $srcx = floor($cx - $srcw / 2) + $offsetx;
        $srcy = $offsety;
    } else {
        $srcw = $oldwidth;
        $srch = floor($height / $ratiow);
        $srcx = $offsetx;
        $srcy = floor($cy - $srch / 2) + $offsety;
    }
    ImageCopyBicubic($resized, $image, 0, 0, $srcx, $srcy, $width, $height, $srcw, $srch);
    return $resized;
}