本文整理汇总了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();
});
//.........这里部分代码省略.........