PHP大图生成缩略图(0 位领导批示)

原贴地址: http://bbs.blueidea.com/thread-2997569-1-1.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
/**
* 生成缩略图
*
* @param string $imagePath 图片路径
* @param string $thumb 生成缩略图名称
* @param integer $width 生成缩略图最大宽度
* @param integer $height 生成缩略图最大高度
* 
* @author Silver 
* @link http://www.zdyi.com
*/
function resizeImage($imagePath, $thumb, $width = 200, $height = 200)
{
    list($imageWidth, $imageHeight) = getimagesize($imagePath);
    $imagePath = imagecreatefromjpeg($imagePath);
    if ($width && ($imageWidth < $imageHeight))
    {
        $width = ($height / $imageHeight) * $imageWidth;
    }
    else
    {
        $height = ($width / $imageWidth) * $imageHeight;
    }
    $image = imagecreatetruecolor($width, $height);
    imagecopyresampled($image, $imagePath, 0, 0, 0, 0, $width, $height, $imageWidth, $imageHeight);
    imagepng($image, $thumb);
    imagedestroy($image);
}
resizeImage('test.jpg', 'test_thumb.jpg');
?>

上传图片附件显示缩略图(3 位领导批示)

刚开始以为很容易解决.写js嘛..-_,-+


< i nput type="file" onchange="document.getElementById('showimg').src=this.value;" />

然而本地测试成功的代码上传到服务器上就出现了错误..空格被自动转义成为了%20

无语ing….囧..

不过总算找到一个BT的方法..用CSS中的AlphaImageLoader滤镜 -_!!

AlphaImageLoader滤镜的使用方法就不做说明..自己查下手册

AlphaImageLoader滤镜的src属就是其中的主角 它将使用绝对或相对url地址指定背景图像。假如忽略此参数,滤镜将不会作用。

放出代码

全文阅读 »

随机显示的10篇日志

评论最多的10篇日志

浏览最多的10篇日志