protected function doCrop(UploadableFile $file, $coordinates, $path)
    {
        $crop = imagecreatetruecolor($coordinates['min_width'], $coordinates['min_height']);

        switch ($file->getExtension()) {
            case 'gif':
                $source = imagecreatefromgif($file); break;

            case 'png':
                $source = imagecreatefrompng($file); break;

            default:
                $source = imagecreatefromjpeg($file);
        }

        if (preg_match('/^(gif|png)$/', $file->getExtension())) {
            imagecolortransparent($crop, imagecolorallocatealpha($crop, 0, 0, 0, 127));
            imagealphablending($crop, false);
            imagesavealpha($crop, true);
        }

        imagecopyresampled(
            $crop, $source,
            0, 0,
            $coordinates['left'], $coordinates['top'],
            $coordinates['min_width'], $coordinates['min_height'],
            $coordinates['width'], $coordinates['height']
        );

        switch ($file->getExtension()) {
            case 'gif':
                imagegif($crop, $path); break;

            case 'png':
                imagepng($crop, $path); break;

            default:
                imagejpeg($crop, $path, 100);
        }
    }