当前位置: 首页>>代码示例>>PHP>>正文


PHP imagecrop函数代码示例

本文整理汇总了PHP中imagecrop函数的典型用法代码示例。如果您正苦于以下问题:PHP imagecrop函数的具体用法?PHP imagecrop怎么用?PHP imagecrop使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了imagecrop函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ocr

 public function ocr($billID, $template)
 {
     $amountImgFileDirectory = "images/detection_result/";
     $dueDateImgFileDirectory = "images/detection_result/";
     $amountImgFileName = "croppedAmt.jpg";
     $dueDateImgFileName = "croppedDueDate.jpg";
     //connect to mysql and getting the coordinate data
     require_once 'TesseractOCR.php';
     $this->billdb->select('billFilePath');
     $this->billdb->where('billID', $billID);
     $query1 = $this->billdb->get('bills');
     //$this->billdb->query("SELECT billFilePath from bills where billID = " . $billID);
     $ini_filename = $query1->result()[0]->billFilePath;
     $im = imagecreatefromjpeg($ini_filename);
     list($width, $height) = getimagesize($ini_filename);
     $query2 = $this->templatedb->query("SELECT coordinateLabelX, coordinateLabelY, coordinateLabelX2, coordinateLabelY2 FROM datafields WHERE templateID = '" . $template . "' AND dataFieldLabel = 'amount'");
     $row = $query2->row(0);
     $x1 = $row->coordinateLabelX;
     $y1 = $row->coordinateLabelY;
     $x2 = $row->coordinateLabelX2 - $row->coordinateLabelX;
     $y2 = $row->coordinateLabelY2 - $row->coordinateLabelY;
     // Scale Up coordinates
     $x1 = $x1 * $width;
     $y1 = $y1 * $height;
     $x2 = $x2 * $width;
     $y2 = $y2 * $height;
     //cropping the image using the coordinate data
     $to_crop_array = array('x' => $x1, 'y' => $y1, 'width' => $x2, 'height' => $y2);
     if ($template != 0) {
         $thumb_im = imagecrop($im, $to_crop_array);
     } else {
         $thumb_im = $im;
     }
     imagejpeg($thumb_im, $amountImgFileDirectory . $amountImgFileName, 100);
     //run OCR on the cropped section
     $tesseract = new TesseractOCR($amountImgFileDirectory . $amountImgFileName);
     $tesseract->setLanguage('eng');
     $amount = $tesseract->recognize();
     $amount = preg_replace("/[^0-9,.]/", "", $amount);
     $query3 = $this->templatedb->query("SELECT coordinateLabelX, coordinateLabelY, coordinateLabelX2, coordinateLabelY2 FROM datafields WHERE templateID = '" . $template . "' AND dataFieldLabel = 'duedate'");
     $row = $query3->row(0);
     $x1 = $row->coordinateLabelX;
     $y1 = $row->coordinateLabelY;
     $x2 = $row->coordinateLabelX2 - $row->coordinateLabelX;
     $y2 = $row->coordinateLabelY2 - $row->coordinateLabelY;
     // Scale Up coordinates
     $x1 = $x1 * $width;
     $y1 = $y1 * $height;
     $x2 = $x2 * $width;
     $y2 = $y2 * $height;
     //cropping the image using the coordinate data
     $to_crop_array = array('x' => $x1, 'y' => $y1, 'width' => $x2, 'height' => $y2);
     if ($template != 0) {
         $thumb_im = imagecrop($im, $to_crop_array);
     } else {
         $thumb_im = $im;
     }
     imagejpeg($thumb_im, $dueDateImgFileDirectory . $dueDateImgFileName, 100);
     //run OCR on the cropped section
     $tesseract = new TesseractOCR($dueDateImgFileDirectory . $dueDateImgFileName);
     $tesseract->setLanguage('eng');
     $duedate = $tesseract->recognize();
     $amount = strtok($amount, " ");
     $day = strtok($duedate, " ");
     $month = strtok(" ");
     $year = strtok(" ");
     str_replace(array(",", "."), "", $day);
     str_replace(array(",", "."), "", $month);
     str_replace(array(",", "."), "", $year);
     if (ctype_alpha($day)) {
         $temp = $day;
         $day = $month;
         $month = $temp;
     }
     switch ($month) {
         case 'Jan':
         case 'January':
             $month = "01";
             break;
         case 'Feb':
         case 'February':
             $month = "02";
             break;
         case 'Mar':
         case 'March':
             $month = "03";
             break;
         case 'Apr':
         case 'April':
             $month = "04";
             break;
         case 'May':
             $month = "05";
             break;
         case 'Jun':
         case 'June':
             $month = "06";
             break;
         case 'Jul':
         case 'July':
//.........这里部分代码省略.........
开发者ID:nus-mtp,项目名称:bill-egoat,代码行数:101,代码来源:Templates_model.php

示例2: actionPhoto

 public function actionPhoto($id)
 {
     $model = $this->loadModel($id);
     $model->scenario = 'photo';
     Yii::trace("FC.actionPhoto called", 'application.controllers.FamilyController');
     if (Yii::app()->params['photoManip']) {
         if (isset($_POST['x1'])) {
             $x1 = $_POST['x1'];
             $y1 = $_POST['y1'];
             $width = $_POST['width'];
             $height = $_POST['height'];
             $pfile = $_POST['pfile'];
             $sdir = './images/uploaded/';
             $size = getimagesize($sdir . $pfile);
             if ($size) {
                 list($w, $h, $t) = $size;
             } else {
                 Yii::trace("FR.actionPhoto crop call to getimagesize failed for image " . $sdir . $pfile . " returned {$size}", 'application.controllers.FamilyController');
             }
             Yii::trace("FC.actionPhoto crop received {$x1}, {$y1}, {$width}, {$height}, {$w}, {$h}, {$t}", 'application.controllers.FamilyController');
             switch ($t) {
                 case 1:
                     $img = imagecreatefromgif($sdir . $pfile);
                     break;
                 case 2:
                     $img = imagecreatefromjpeg($sdir . $pfile);
                     break;
                 case 3:
                     $img = imagecreatefrompng($sdir . $pfile);
                     break;
                 case IMAGETYPE_BMP:
                     $img = ImageHelper::ImageCreateFromBMP($sdir . $pfile);
                     break;
                 case IMAGETYPE_WBMP:
                     $img = imagecreatefromwbmp($sdir . $pfile);
                     break;
                 default:
                     Yii::trace("FC.actionPhoto crop unknown image type {$t}", 'application.controllers.FamilyController');
             }
             if (function_exists('imagecrop')) {
                 # untested
                 $cropped = imagecrop($img, array('x1' => $x1, 'y1' => $y1, 'width' => $width, 'height' => $height));
                 $scaled = imagescale($cropped, 400);
             } else {
                 $h = $height * 400 / $width;
                 $scaled = imagecreatetruecolor(400, $h);
                 imagecopyresized($scaled, $img, 0, 0, $x1, $y1, 400, $h, $width, $height);
             }
             $dir = './images/families/';
             $fname = preg_replace('/\\.[a-z]+$/i', '', $pfile);
             $fext = ".jpg";
             if (file_exists($dir . $pfile)) {
                 $fname .= "_01";
                 while (file_exists($dir . $fname . $fext)) {
                     ++$fname;
                 }
             }
             $dest = $dir . $fname . $fext;
             imagejpeg($scaled, $dest, 90);
             imagedestroy($scaled);
             imagedestroy($img);
             unlink($sdir . $pfile);
             $model->photo = $fname . $fext;
             $model->save(false);
             Yii::trace("FC.actionPhoto saved to {$pfile}", 'application.controllers.FamilyController');
             $this->redirect(array('view', 'id' => $model->id));
             return;
         } elseif (isset($_FILES['Families'])) {
             Yii::trace("FC.actionPhoto _FILES[Families] set", 'application.controllers.FamilyController');
             $files = $_FILES['Families'];
             $filename = $files['name']['raw_photo'];
             if (isset($filename) and '' != $filename) {
                 Yii::trace("FC.actionPhoto filename {$filename}", 'application.controllers.FamilyController');
                 $tmp_path = $files['tmp_name']['raw_photo'];
                 if (isset($tmp_path) and '' != $tmp_path) {
                     Yii::trace("FC.actionPhoto tmp_path {$tmp_path}", 'application.controllers.FamilyController');
                     $dir = "./images/uploaded/";
                     $dest = $dir . $filename;
                     list($width, $height) = getimagesize($tmp_path);
                     if ($width < 900) {
                         $w = $width;
                         $h = $height;
                         $zoom = 1;
                     } else {
                         $w = 900;
                         $h = $height * 900 / $width;
                         $zoom = $w / $width;
                     }
                     $w = $width < 900 ? $width : 900;
                     move_uploaded_file($tmp_path, $dest);
                     $this->render('crop', array('model' => $model, 'pfile' => $filename, 'width' => $w, 'height' => $h, 'zoom' => $zoom));
                     return;
                 } else {
                     $errors = array(1 => "Size exceeds max_upload", 2 => "FORM_SIZE", 3 => "No tmp dir", 4 => "can't write", 5 => "error extension", 6 => "error partial");
                     $error = $errors[$files['error']['raw_photo']];
                     Yii::trace("FC.actionPhoto file error {$error}", 'application.controllers.FamilyController');
                 }
             }
         }
     } elseif (isset($_FILES['Families'])) {
//.........这里部分代码省略.........
开发者ID:srinidg,项目名称:stbennos-parish,代码行数:101,代码来源:FamilyController.php

示例3: upload

 public function upload(Request $request)
 {
     $data = $request->input('photo');
     if ($data) {
         list($type, $data) = explode(';', $data);
         list(, $data) = explode(',', $data);
         $data = base64_decode($data);
         $meta = $request->input('meta');
         $extension = explode('/', $meta['type'])[1];
         $file = md5(microtime(true)) . '.' . $extension;
         $crop = $request->input('crop');
         $src = imagecreatefromstring($data);
         if ($src = imagecrop($src, array('x' => $crop['x'], 'y' => $crop['y'], 'width' => $crop['width'], 'height' => $crop['height']))) {
             switch ($extension) {
                 case 'jpg':
                 case 'jpeg':
                     imagejpeg($src, './uploads/' . $file);
                     break;
                 case 'gif':
                     imagegif($src, './uploads/' . $file);
                     break;
                 case 'png':
                     imagepng($src, './uploads/' . $file);
                     break;
             }
             return json_encode(['file' => $file, 'url' => "http://{$_SERVER['HTTP_HOST']}/uploads/{$file}"]);
         }
     }
     return '上传失败';
 }
开发者ID:xuhongxu96,项目名称:tagexing2,代码行数:30,代码来源:UploadController.php

示例4: getTextFromImage

function getTextFromImage($file)
{
    $background = imagecreatefromjpeg('background.jpg');
    $image = imagecreatefromstring($file);
    $black = imagecolorallocate($image, 0, 0, 0);
    $min_visible_y = $max_y = imagesy($image);
    $min_visible_x = $max_x = imagesx($image);
    $max_visible_x = $max_visible_y = 0;
    for ($y = 0; $y < $max_y; $y++) {
        for ($x = 0; $x < $max_x; $x++) {
            $pixel = ImageColorAt($image, $x, $y);
            $colors = imagecolorsforindex($image, $pixel);
            $pixel_bg = ImageColorAt($background, $x, $y);
            $colors_bg = imagecolorsforindex($background, $pixel_bg);
            $range = 35;
            if ($colors['red'] + $range > $colors_bg['red'] && $colors['red'] - $range < $colors_bg['red']) {
                imagesetpixel($image, $x, $y, $black);
            } else {
                $min_visible_x = $min_visible_x > $x ? $x : $min_visible_x;
                $max_visible_x = $max_visible_x < $x ? $x : $max_visible_x;
                $min_visible_y = $min_visible_y > $y ? $y : $min_visible_y;
                $max_visible_y = $max_visible_y < $y ? $y : $max_visible_y;
            }
        }
    }
    $image = imagecrop($image, ['x' => $min_visible_x, 'y' => $min_visible_y, 'width' => $max_visible_x, 'height' => $max_visible_y]);
    imagefilter($image, IMG_FILTER_GRAYSCALE);
    $tmpfname = tempnam("/tmp", "OCR");
    imagepng($image, $tmpfname);
    $txt = $ocr->recognize($tmpfname, ['eng'], 3);
    unlink($tmpfname);
    return str_replace("\n", "", $txt);
}
开发者ID:vitormattos,项目名称:ocr-test,代码行数:33,代码来源:index.php

示例5: image_crop

 function image_crop($src_img, $filename, $final_path, $temp_file_path, $mime)
 {
     $to_crop_array = array('x' => 0, 'y' => 0, 'width' => 900, 'height' => 400);
     $new_image = imagecrop($src_img, $to_crop_array);
     $new_file_path = $final_path . $filename;
     unlink($temp_file_path);
     return $this->create_image($new_image, $new_file_path, $mime);
 }
开发者ID:vinayadahal,项目名称:practice,代码行数:8,代码来源:image_resize.php

示例6: save

 public function save($file_name)
 {
     if (file_exists($file_name)) {
         throw new \Exception("Save File Already Exists ({$file_name})");
     }
     $to_crop = ['x' => $this->face['x'] - $this->padding_width / 2, 'y' => $this->face['y'] - $this->padding_height / 2, 'width' => $this->face['w'] + $this->padding_width, 'height' => $this->face['w'] + $this->padding_height];
     $this->cropped_canvas = imagecrop($this->canvas, $to_crop);
     imagejpeg($this->cropped_canvas, $file_name, 100);
 }
开发者ID:softon,项目名称:laravel-face-detect,代码行数:9,代码来源:FaceDetect.php

示例7: upload

 function upload()
 {
     $idu = isset($_SESSION['idu']) ? $_SESSION['idu'] : 0;
     $this->stat->saveStat($idu, "photo/upload");
     if ($idu > 0) {
         if (isset($_FILES['add-photo'])) {
             //                 var_dump($_FILES['add-photo']);
             $tmpFile = $_FILES['add-photo']['tmp_name'];
             $info = getimagesize($tmpFile);
             $width = $info[0];
             $height = $info[1];
             $mime = $info['mime'];
             if ($width != null && $height != null) {
                 $md = md5(time());
                 $path = rtrim(LOCAL_DIR_PHOTO, '/\\') . '/';
                 $dir = $path . $idu . '/';
                 if (!is_dir($dir)) {
                     mkdir($dir, 0777, true);
                 }
                 $fileName = $idu . '/' . $md . '.jpg';
                 $fileFullPath = $path . $fileName;
                 if ($mime == 'image/jpeg') {
                     $image = imagecreatefromjpeg($tmpFile);
                 }
                 if ($mime == 'image/png') {
                     $image = imagecreatefrompng($tmpFile);
                 }
                 if (isset($image)) {
                     $side = min($width, $height);
                     $rect = array('x' => 0, 'y' => 0, 'width' => $side, 'height' => $side);
                     $imageThumb = imagecreatetruecolor(PHOTO_SIZE, PHOTO_SIZE);
                     $image = imagecrop($image, $rect);
                     imagecopyresampled($imageThumb, $image, 0, 0, 0, 0, PHOTO_SIZE, PHOTO_SIZE, $side, $side);
                     imagejpeg($imageThumb, $fileFullPath, 80);
                     $model = new Model_Profile();
                     $model->uploadPhoto($idu, $fileName);
                     imagedestroy($image);
                     imagedestroy($imageThumb);
                 } else {
                     header('Location:' . WEB_APP . '/photo/');
                     return;
                 }
             } else {
                 header('Location:' . WEB_APP . '/photo/');
                 return;
             }
         }
         header('Location:' . WEB_APP . '/profile/');
     } else {
         unset($_SESSION['idu']);
         header('Location:' . WEB_APP);
     }
 }
开发者ID:aliasnash,项目名称:flirt-web-p,代码行数:53,代码来源:photo.php

示例8: cropImage

 /**
  * Function to reduce code size in __async_edit method
  * @param resource $imageResource Image to crop
  * @return bool|resource Cropped image
  */
 public function cropImage($imageResource)
 {
     /** @var int $imageTransparency Transparent color */
     $imageTransparency = imagecolorallocatealpha($imageResource, 255, 255, 255, 127);
     /** @var resource $rotatedImage Rotated image resource */
     $rotatedImage = imagerotate($imageResource, -$_POST['rotate'], $imageTransparency);
     /** @var resource $croppedImage Cropped image resource */
     $croppedImage = imagecrop($rotatedImage, array('x' => $_POST['crop_x'], 'y' => $_POST['crop_y'], 'width' => $_POST['crop_width'], 'height' => $_POST['crop_height']));
     // Delete temp image resource
     imagedestroy($rotatedImage);
     // Return cropped image
     return $croppedImage;
 }
开发者ID:samsoncms,项目名称:gallery,代码行数:18,代码来源:Editor.php

示例9: crop

 public function crop($x, $y, $width, $height, $filename)
 {
     $cropArray = array('x' => $x, 'y' => $y, 'width' => $width, 'height' => $height);
     Debugger::debug($cropArray);
     $thumb_im = imagecrop($this->image, $cropArray);
     //$filename = PUBLIC_ROOT . $filename;
     if ($this->imageType == IMAGETYPE_JPEG) {
         imagejpeg($thumb_im, $filename, 100);
     } elseif ($this->imageType == IMAGETYPE_GIF) {
         imagegif($thumb_im, $filename);
     } elseif ($this->imageType == IMAGETYPE_PNG) {
         imagepng($thumb_im, $filename);
     }
     chmod($filename, 0777);
 }
开发者ID:lenlyle1,项目名称:lightupdating,代码行数:15,代码来源:CropTools.php

示例10: cropImage

 /**
  * crop image
  *
  * @param  string $imagePathname
  * @param  string $prefix
  * @param  array $selection
  * @return array
  */
 protected function cropImage($imagePathname, $prefix, $selection)
 {
     // $destinationPath
     $destinationPath = public_path('resource\\' . $prefix);
     // checkImage and get type
     $type = $this->checkImage($imagePathname);
     // generate image name
     $imageName = $this->generateImageName($prefix, $type);
     // create image resource
     $imageResource = $this->createImageResource($imagePathname, $type);
     // crop image resource
     $imageCroppedResource = imagecrop($imageResource, $selection);
     // save image to destination
     imagejpeg($imageCroppedResource, "{$destinationPath}\\" . $imageName);
     // image url
     $imageUrl = url('resource/' . "{$prefix}/" . $imageName);
     return ['imgPathname' => $destinationPath . $imageName, 'imgUrl' => $imageUrl];
 }
开发者ID:weiyeu,项目名称:laravel_date,代码行数:26,代码来源:ImageProcessor.php

示例11: resizeImage

 public function resizeImage($width, $height = 0, $crop = false)
 {
     $this->ImgNewHeight = $height;
     $this->ImgNewWidth = $width;
     $this->Crop = $crop;
     $this->calcSize();
     $this->NewImgRes = imagecreatetruecolor($this->ImgResizeNewWidth, $this->ImgResizeNewHeight);
     // изменение размера
     if (imagecopyresampled($this->NewImgRes, $this->ImgRes, 0, 0, 0, 0, $this->ImgResizeNewWidth, $this->ImgResizeNewHeight, $this->ImgWidth, $this->ImgHeight)) {
         imagedestroy($this->ImgRes);
         $this->ImgRes = $this->NewImgRes;
         if ($crop) {
             $y = round($this->ImgResizeNewHeight / 2) - round($this->ImgNewHeight / 2);
             $this->ImgRes = imagecrop($this->ImgRes, array('x' => 0, 'y' => $y, 'width' => $this->ImgNewWidth, 'height' => $this->ImgNewHeight));
         }
         $this->ImgWidth = $this->ImgNewWidth;
         $this->ImgHeight = $this->ImgNewHeight;
     } else {
         throw new \Exception('imagecopyresampled Error');
     }
 }
开发者ID:sblazheev,项目名称:yii2-imagehelper,代码行数:21,代码来源:GdImageOperation.php

示例12: crop

 /**
  * Resample image
  * @param $width
  * @param $height
  * @param $x
  * @param $y
  * @throws SPException
  * @return bool
  */
 public function crop($width, $height, $x = 0, $y = 0)
 {
     //		if ( !( function_exists( 'imagecrop' ) ) ) {
     //			throw new SPException( 'Function "imagecrop" is not available on this server' );
     //		}
     if (!$this->_content) {
         $this->read();
     }
     list($wOrg, $hOrg, $imgType) = getimagesize($this->_filename);
     $this->type = $imgType;
     $currentImg = $this->createImage($imgType);
     if (function_exists('imagecrop')) {
         $this->image = imagecrop($currentImg, array('x' => $x, 'y' => $y, 'width' => $width, 'height' => $height));
     } else {
         // imagecopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h )
         $this->image = imagecreatetruecolor($width, $height);
         imagecopy($this->image, $currentImg, 0, 0, $x, $y, $width, $height);
     }
     if ($imgType == IMAGETYPE_GIF || $imgType == IMAGETYPE_PNG) {
         $this->transparency($this->image);
     }
     $this->storeImage();
 }
开发者ID:ranrolls,项目名称:ras-full-portal,代码行数:32,代码来源:image.php

示例13: actionIndex

 public function actionIndex()
 {
     $object = new ExampleModel();
     if (Yii::$app->request->isPost) {
         // get post data
         $object->load(Yii::$app->request->post());
         $object->file_attribute = UploadedFile::getInstance($object, 'file_attribute');
         if ($object->validate()) {
             $object->save();
             // lets get the image and crop it with the data passed via post from the form
             // this example is, for obvious reasons, only valid for jpeg image files.
             // This is already setted as a rule, so no sweat about it.
             $newimage = 'images/' . $object->file_attribute->baseName . '.' . $object->file_attribute->extension;
             $object->file_attribute->saveAs($newimage);
             $cropping_data = Yii::$app->request->post('file_attribute-cropping');
             $im = imagecreatefromjpeg($newimage);
             $thumb_im = imagecrop($im, $cropping_data);
             imagejpeg($thumb_im, $newimage, 100);
             return 'File cropped successfully!';
         }
     } else {
         return $this->render('index', ['object' => $object]);
     }
 }
开发者ID:dpodium,项目名称:yii2-widget-upload-crop,代码行数:24,代码来源:UploadController.php

示例14: imagecolorallocate

        $color = imagecolorallocate($img, $r, $g, $b);
        imagefilledrectangle($img, $x, $y + $i, $x1, $y + $i + 1, $color);
    }
    return true;
}
$im = imagecreate($_GET['width'], $_GET['height']);
$bg = imagecolorallocate($im, 150, 150, 150);
$black = imagecolorallocate($im, 0, 0, 0);
image_gradientrect($im, 0, 0, $_GET['width'], $_GET['height'], 'FF0000', '0000FF');
for ($i = 0; $i <= $_GET['width']; $i += 100) {
    imageline($im, $i - 1, 0, $i - 1, $_GET['height'], $black);
    imageline($im, $i, 0, $i, $_GET['height'], $black);
}
for ($i = 0; $i <= $_GET['height']; $i += 100) {
    imageline($im, 0, $i - 1, $_GET['width'], $i - 1, $black);
    imageline($im, 0, $i, $_GET['width'], $i, $black);
}
for ($y = 0; $y <= $_GET['height']; $y += 100) {
    for ($x = 0; $x <= $_GET['width']; $x += 100) {
        $i = $y / 100;
        $j = $x / 100;
        imagestring($im, 3, $x + 6, $y + 2, "{$i}, {$j}", $textcolor);
    }
}
if (isset($_GET['crop'])) {
    list($cropX, $cropY, $cropWidth, $cropHeight) = explode(',', $_GET['crop']);
    $im = imagecrop($im, ['x' => $cropX, 'y' => $cropY, 'width' => $cropWidth, 'height' => $cropHeight]);
}
header("Content-type: image/png");
imagepng($im);
imagedestroy($im);
开发者ID:roelvanduijnhoven,项目名称:reverse-image-cover,代码行数:31,代码来源:image.php

示例15: transform

 /**
  * Apply transformations on image
  *
  * @param string $source Source image
  * @param array  $params Transformations and parameters
  * @param string $store  Temporary store on disk
  *
  * @return string
  */
 public function transform($source, $params, $store = null)
 {
     $image = $this->_getImageAsResource($source);
     $result = null;
     if (isset($params['negate'])) {
         $res = imagefilter($image, IMG_FILTER_NEGATE);
         if ($res === false) {
             throw new \RuntimeException(_('Something went wrong in GD negate!'));
         }
     }
     if (isset($params['contrast'])) {
         $res = imagefilter($image, IMG_FILTER_CONTRAST, $params['contrast'] * -10);
         if ($res === false) {
             throw new \RuntimeException(_('Something went wrong in GD contrast!'));
         }
     }
     if (isset($params['brightness'])) {
         $res = imagefilter($image, IMG_FILTER_BRIGHTNESS, $params['brightness'] * 2.55);
         if ($res === false) {
             throw new \RuntimeException(_('Something went wrong in GD brightness!'));
         }
     }
     if (isset($params['rotate'])) {
         $result = imagerotate($result !== null ? $result : $image, 360 - $params['rotate']['angle'], 0);
         if ($result === null) {
             throw new \RuntimeException(_('Something went wrong in GD rotation!'));
         }
     }
     if (isset($params['crop'])) {
         $cparams = array('x' => $params['crop']['x'], 'y' => $params['crop']['y'], 'width' => $params['crop']['w'], 'height' => $params['crop']['h']);
         $infos = $this->getImageInfos($source);
         $orig_width = $infos[0];
         $orig_height = $infos[1];
         if (isset($params['rotate']) && ($params['rotate']['angle'] == 90 || $params['rotate']['angle'] == 270)) {
             $orig_width = $infos[1];
             $orig_height = $infos[0];
         }
         if ($orig_width < $cparams['width']) {
             $cparams['width'] = $orig_width;
         }
         if ($orig_height < $cparams['height']) {
             $cparams['height'] = $orig_height;
         }
         $result = imagecrop($result !== null ? $result : $image, $cparams);
         if ($result === null) {
             throw new \RuntimeException(_('Something went wrong in GD crop!'));
         }
     }
     if ($result === null) {
         $result = $image;
     }
     imagejpeg($result, $store);
     imagedestroy($result);
 }
开发者ID:Anaphore,项目名称:viewer,代码行数:63,代码来源:GdHandler.php


注:本文中的imagecrop函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。