當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ImageManagerStatic::getHttpResponseCode方法代碼示例

本文整理匯總了PHP中Intervention\Image\ImageManagerStatic::getHttpResponseCode方法的典型用法代碼示例。如果您正苦於以下問題:PHP ImageManagerStatic::getHttpResponseCode方法的具體用法?PHP ImageManagerStatic::getHttpResponseCode怎麽用?PHP ImageManagerStatic::getHttpResponseCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Intervention\Image\ImageManagerStatic的用法示例。


在下文中一共展示了ImageManagerStatic::getHttpResponseCode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: process

 function process()
 {
     $param = $this->param;
     $image_path = $original_file = $this->image_path;
     $settings = $this->settings;
     $image_quality = intval($settings['image']['quality']);
     Utils::log($image_path, "Reading image");
     $img = Image::make($image_path);
     $mime = $img->mime();
     Utils::log($img->getWidth() . " X " . $img->getHeight(), "Dimensions");
     Utils::log($img->mime(), "Mime");
     Utils::log($image_quality, "Quality");
     // Calculate the correct dimensions. If necessary, avoid upscaling the image.
     $src_w = $img->getWidth();
     $src_h = $img->getHeight();
     if ($settings['image']['disable_upscaling'] == 'yes') {
         $dst_w = min($param->width, $src_w);
         $dst_h = min($param->height, $src_h);
     } else {
         $dst_w = $param->width;
         $dst_h = $param->height;
     }
     //$this->output_format = FORMAT_GIF;
     if ($this->output_format != 'default') {
         $img = $img->encode($this->output_format, $image_quality);
     }
     Utils::log($img->mime(), "Mime");
     // If there is no mode for the requested image, just read the image
     // from it's location (which may be external)
     // http://yajit.test/i/0/public/foo.jpg
     if ($param->mode == MODE_NONE) {
         if ($param->external && Image::getHttpResponseCode($original_file) != 200 || $param->external === FALSE && (!file_exists($original_file) || !is_readable($original_file))) {
             // Guess not, return 404.
             Page::renderStatusCode(Page::HTTP_STATUS_NOT_FOUND);
             trigger_error(sprintf('Image <code>%s</code> could not be found.', str_replace(DOCROOT, '', $original_file)), E_USER_ERROR);
             echo sprintf('Image <code>%s</code> could not be found.', str_replace(DOCROOT, '', $original_file));
             exit;
         }
     }
     switch ($param->mode) {
         // http://yajit.test/i/1/80/80/public/foo.jpg
         case MODE_RESIZE:
             // resize image to fixed size
             $img->resize($dst_w, $dst_h);
             break;
             // http://yajit.test/i/4/300/200/public/foo.jpg
         // http://yajit.test/i/4/300/200/public/foo.jpg
         case MODE_FIT:
             // resize image to fit size
             if ($param->height == 0) {
                 $ratio = $src_h / $src_w;
                 $dst_h = round($dst_w * $ratio);
             } else {
                 if ($param->width == 0) {
                     $ratio = $src_w / $src_h;
                     $dst_w = round($dst_h * $ratio);
                 }
             }
             $src_r = $src_w / $src_h;
             $dst_r = $dst_w / $dst_h;
             Utils::log("src_w: {$src_w} src_h: {$src_h} dst_w:{$dst_w} dst_h:{$dst_h} src_r:{$src_r} dst_r:{$dst_r}");
             if ($src_h <= $dst_h && $src_w <= $dst_w) {
                 //$image->applyFilter('resize', array($src_w, $src_h));
                 Utils::log("img->resize({$dst_w}, {$dst_h})");
                 $img->resize($dst_w, $dst_h);
                 break;
             }
             if ($src_h >= $dst_h && $src_r <= $dst_r) {
                 //$image->applyFilter('resize', array(NULL, $dst_h));
                 Utils::log("img->resize(null, {$dst_h})");
                 $img->resize(NULL, $dst_h, function ($constraint) {
                     $constraint->aspectRatio();
                 });
             }
             if ($src_w >= $dst_w && $src_r >= $dst_r) {
                 //$image->applyFilter('resize', array($dst_w, NULL));
                 Utils::log("img->resize({$dst_w}, null)");
                 $img->resize($dst_w, NULL, function ($constraint) {
                     $constraint->aspectRatio();
                 });
             }
             break;
             // http://yajit.test/i/2/500/500/2/public/foo.jpg
         // http://yajit.test/i/2/500/500/2/public/foo.jpg
         case MODE_RESIZE_CROP:
             if ($param->height == 0) {
                 $ratio = $src_h / $src_w;
                 $dst_h = round($dst_w * $ratio);
             } else {
                 if ($param->width == 0) {
                     $ratio = $src_w / $src_h;
                     $dst_w = round($dst_h * $ratio);
                 }
             }
             $src_r = $src_w / $src_h;
             $dst_r = $dst_w / $dst_h;
             if ($src_r < $dst_r) {
                 $img->resize($dst_w, NULL, function ($constraint) {
                     $constraint->aspectRatio();
                 });
//.........這裏部分代碼省略.........
開發者ID:n3m3s7s,項目名稱:yajit,代碼行數:101,代碼來源:Yajit.php


注:本文中的Intervention\Image\ImageManagerStatic::getHttpResponseCode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。