日期:2011-12-29  浏览次数:20563 次

  在PHP网站开发过程中,如果你建立的网站涉及大量的图片处理,必然涉及到图片上传,缩放,而如何保持图片不失真,是很多初级PHP网站开发者比较头疼的一件事,今天David就和大家分享一下如何进行图片缩放。使用之前你需要下载安装GD库,以支持PHP图片处理。下面我们结合代码讲解具体的PHP图片缩放处理的思路。

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
function resizeImage($im,$maxwidth,$maxheight,$name,$filetype)
{
    $pic_width = imagesx($im);
    $pic_height = imagesy($im);

    if(($maxwidth && $pic_width > $maxwidth) ($maxheight && $pic_height > $maxheight))
    {
        if($maxwidth && $pic_width>$maxwidth)
        {
            $widthratio = $maxwidth/$pic_width;
            $resizewidth_tag = true;
        }

        if($maxheight && $pic_height>$maxheight)
        {
            $heightratio = $maxheight/$pic_height;
            $resizeheight_tag =