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

2013-12-11 11:26:45 +08:00
 akaayy
好像曾在v2ex某个角落看到过有这样的类,不知道是否我误解。

大概场景是这样的

已知图片地址是 /logo.gif

我在页面写<img src="/showPic.php?url=/log.gif&w=110&h=50">
这样打开的是一个长宽为110*50的图片,不管原来是多大
2846 次点击
所在节点    问与答
6 条回复
faceair
2013-12-11 11:33:00 +08:00
七牛可以
markmx
2013-12-11 11:36:53 +08:00
自己也可以是实现的。 你这样的话 就需要每次都要转格式了吧。。
manhere
2013-12-11 11:40:04 +08:00
http://avnpc.com/pages/evathumber
你可能说的是这个
akaayy
2013-12-11 11:44:30 +08:00
akaayy
2013-12-11 11:45:16 +08:00
akaayy
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);
}
?>
-----------------------------------------------------

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/92682

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX