duangua5742 2011-03-01 17:23
浏览 69
已采纳

将全景图像调整为固定大小

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 this image: enter image description here

Here's my code:

<?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.

  • 写回答

4条回答 默认 最新

  • dongya5893 2011-03-01 17:26
    关注

    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;
    ?>
    

    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.

    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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 KeiI中头文件找不到怎么解决
  • ¥15 QT6将音频采样数据转PCM
  • ¥15 本地安装org.Hs.eg.dby一直这样的图片报错如何解决?
  • ¥15 下面三个文件分别是OFDM波形的数据,我的思路公式和我写的成像算法代码,有没有人能帮我改一改,如何解决?
  • ¥15 Ubuntu打开gazebo模型调不出来,如何解决?
  • ¥100 有chang请一位会arm和dsp的朋友解读一个工程
  • ¥50 求代做一个阿里云百炼的小实验
  • ¥15 查询优化:A表100000行,B表2000 行,内存页大小只有20页,运行时3页,设计两个表等值连接的最简单的算法
  • ¥15 led数码显示控制(标签-流程图)
  • ¥20 为什么在复位后出现错误帧