akaayy
V2EX  ›  问与答

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

  •  
  •   akaayy · Dec 11, 2013 · 3439 views
    This topic created in 4710 days ago, the information mentioned may be changed or developed.
    好像曾在v2ex某个角落看到过有这样的类,不知道是否我误解。

    大概场景是这样的

    已知图片地址是 /logo.gif

    我在页面写<img src="/showPic.php?url=/log.gif&w=110&h=50">
    这样打开的是一个长宽为110*50的图片,不管原来是多大
    6 replies  •  1970-01-01 08:00:00 +08:00
    faceair
    faceair
    Dec 11, 2013 via Android
    1
    七牛可以
    markmx
    markmx
    Dec 11, 2013
    2
    自己也可以是实现的。 你这样的话 就需要每次都要转格式了吧。。
    manhere
    manhere
    Dec 11, 2013
    3
    http://avnpc.com/pages/evathumber
    你可能说的是这个
    akaayy
    akaayy
    OP
    Dec 11, 2013
    5
    akaayy
    akaayy
    OP
    Dec 11, 2013
    6
    @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);
    }
    ?>
    -----------------------------------------------------
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1561 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 17:41 · PVG 01:41 · LAX 09:41 · JFK 12:41
    ♥ Do have faith in what you're doing.