V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
akaayy
V2EX  ›  问与答

找这样一个php类,打开一个url,url包含地址、大小信息,获取图片的临时缩略图,好像在v2ex看过的

  •  
  •   akaayy · 2013-12-11 11:26:45 +08:00 · 2840 次点击
    这是一个创建于 3812 天前的主题,其中的信息可能已经有所发展或是发生改变。
    好像曾在v2ex某个角落看到过有这样的类,不知道是否我误解。

    大概场景是这样的

    已知图片地址是 /logo.gif

    我在页面写<img src="/showPic.php?url=/log.gif&w=110&h=50">
    这样打开的是一个长宽为110*50的图片,不管原来是多大
    6 条回复    1970-01-01 08:00:00 +08:00
    faceair
        1
    faceair  
       2013-12-11 11:33:00 +08:00 via Android
    七牛可以
    markmx
        2
    markmx  
       2013-12-11 11:36:53 +08:00
    自己也可以是实现的。 你这样的话 就需要每次都要转格式了吧。。
    manhere
        3
    manhere  
       2013-12-11 11:40:04 +08:00
    http://avnpc.com/pages/evathumber
    你可能说的是这个
    akaayy
        5
    akaayy  
    OP
       2013-12-11 11:45:16 +08:00
    akaayy
        6
    akaayy  
    OP
       2013-12-11 14:54:44 +08:00
    @manhere 你收的这个功能很强大,挺不错,不过还要安装
    我在我发的那个地址里找到了一个符合我要求的一段,很简洁的,可以直接使用
    保存为utf-8编码的时候出错了,改为ansi就正常了

    -----------------------------------------------------
    Resize image proportionaly where you give a max width or max height

    <?php
    header('Content-type: image/jpeg');
    //$myimage = resizeImage('filename', 'newwidthmax', 'newheightmax');
    $myimage = resizeImage('test.jpg', '150', '120');
    print $myimage;

    function resizeImage($filename, $newwidth, $newheight){
    list($width, $height) = getimagesize($filename);
    if($width > $height && $newheight < $height){
    $newheight = $height / ($width / $newwidth);
    } else if ($width < $height && $newwidth < $width) {
    $newwidth = $width / ($height / $newheight);
    } else {
    $newwidth = $width;
    $newheight = $height;
    }
    $thumb = imagecreatetruecolor($newwidth, $newheight);
    $source = imagecreatefromjpeg($filename);
    imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    return imagejpeg($thumb);
    }
    ?>
    -----------------------------------------------------
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   829 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 20:34 · PVG 04:34 · LAX 13:34 · JFK 16:34
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.