代码之家  ›  专栏  ›  技术社区  ›  Karthik

在php中有创建缩略图的功能吗?

  •  -3
  • Karthik  · 技术社区  · 14 年前

    在php中有创建缩略图的功能吗?

    2 回复  |  直到 14 年前
        1
  •  3
  •   Andy E    14 年前

    没有一个函数可以为您创建缩略图,但是有几个函数是GD库的一部分,比如 imagecreatetruecolor imagecopyresampled . 你能做的最好的事情就是从一个教程开始,谷歌知道这里:

    http://www.google.co.uk/search?q=gd+php+thumbnail

        2
  •  1
  •   Prabhu Murthi    14 年前

    你有一个GD库函数来创建图片…请按照网址

    http://php.net/manual/en/book.image.php
    
        3
  •  0
  •   Ajinkya Bodade    5 年前

                $sourceAppImgPath = $this->images->absPath($img);
                $file_dimensions = getimagesize($sourceAppImgPath);
                $ImageType = strtolower($file_dimensions['mime']);
    
                    switch(strtolower($ImageType))
                    {
                        case 'image/png':
                            $image = imagecreatefrompng($sourceAppImgPath);
                            break;
                        case 'image/gif':
                            $image = imagecreatefromgif($sourceAppImgPath);
                            break;
                        case 'image/jpeg':
                            $image = imagecreatefromjpeg($sourceAppImgPath);
                            break;
                        default:
                            return false; //output error
                    }
    
                        $origWidth = imagesx($image);
                        $origHeight = imagesy($image);
                        $maxWidth = 300;
                        $maxHeight =300;
    
                        if ($maxWidth == 0)
                            $maxWidth  = $origWidth;
    
                        if ($maxHeight == 0)
                            $maxHeight = $origHeight;
    
                        $widthRatio = $maxWidth / $origWidth;
                        $heightRatio = $maxHeight / $origHeight;
                        $ratio = min($widthRatio, $heightRatio);
                        $thumb_width  = (int)$origWidth  * $ratio;
                        $thumb_height = (int)$origHeight * $ratio;