本文介绍了将全景图像调整为固定大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将图像调整为固定的宽度和高度(即 150 像素).但是,有一个问题,如果原始照片(例如全景照片)的高度和宽度差异很大,则调整后的缩略图看起来很糟糕.是否有任何智能解决方案可以将照片调整为固定的宽度和高度?例如,请看看这个图像:

I want to resize the images to fixed width and height (i.e. 150px). However, theres a problem, if there is lots of difference in height and width of original photo (for example, panoramic photo), the resized thumbnail looks bad. Is there any any smart solution to resize the photos to a fixed width and height? For example, please have a look at thisimage:

这是我的代码:

<?php
    $params = getimagesize($tempFile);
    $width = $params[0];
    $height = $params[1];

    $newwidth=150;
    $newheight= 150;
    $tmp=imagecreatetruecolor($newwidth,$newheight);

    imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
    imagejpeg($tmp,$img_name,80);

    imagedestroy($src);
    imagedestroy($tmp);
?>

有什么聪明的方法可以智能地调整图像大小吗?谢谢.

Is there any smart way to resize the images in smart way?Thanks.

推荐答案

有一个聪明的解决方案,叫做Seam Carving,如果你的服务器支持 ImageMagick,你可以这样做:

There's a smart solution, it's called Seam Carving, and if your server supports ImageMagick, you do it like this:

<?php
$im = new Imagick( 'image.jpg' );
$im->liquidRescaleImage( 600, 100, 3, 25 );
header( 'Content-Type: image/jpg' );
echo $im;
?>

或者,如果它不支持,请使用 exec()(小心),以便将图像作为参数传递给可执行缝线雕刻.

Or alternatively, if it doesn't support, use exec() (carefully) in order to pass image as an argument to executable which can perform seam carving.

顺便说一句,它看起来像 twitpic 只是裁剪了平方图像提取物.在我之前的一个项目中,我使用了以下代码:

BTW it looks like twitpic just crop's the squared image extract.In one of my previous projects I used following code:

if ($image->width > $image->height){
    //crop image in proportions 4/3, then resize to 500x300 (or proportionally lower resolution),
    //sharp it a little and decrease quality.
    //I used one of the Yii framework extensions.
    $image->crop($image->width, $image->width/4*3)->resize(500, 300, Image::WIDTH)->sharpen(15)->quality(75);
}

这篇关于将全景图像调整为固定大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 15:06