Ignore:
Timestamp:
Apr 16, 2015 11:47:15 AM (10 years ago)
Author:
quyenla
Message:

thumbnail

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pro-violet-viettel/www/deploy/api/platform/lib/violetUtil.class.php

    r784 r894  
    3838    }
    3939  }
     40   public function createThumb($pathToImage="") {
     41
     42        if (is_file($pathToImage)) {
     43     
     44            $info = pathinfo($pathToImage);
     45            $extension = strtolower($info['extension']);
     46           
     47            if (in_array($extension, array('jpg', 'jpeg', 'png', 'gif'))) {
     48
     49                switch ($extension) {
     50                    case 'jpg':
     51                        $img = imagecreatefromjpeg("{$pathToImage}");
     52                        break;
     53                    case 'jpeg':
     54                        $img = imagecreatefromjpeg("{$pathToImage}");
     55                        break;
     56                    case 'png':
     57                        $img = imagecreatefrompng("{$pathToImage}");
     58                        break;
     59                    case 'gif':
     60                        $img = imagecreatefromgif("{$pathToImage}");
     61                        break;
     62                    default:
     63                        $img = imagecreatefromjpeg("{$pathToImage}");
     64                }
     65                list($width, $height) = getimagesize($pathToImage);
     66                $new_width = 64;
     67                $new_height = 50;
     68                $image_p = imagecreatetruecolor($new_width, $new_height);
     69         
     70                imagecopyresampled($image_p, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
     71                $thumnail = $info['dirname']."/".$info['filename']."_thumb.jpg";
     72                imagejpeg($image_p,$thumnail, 30);
     73                return str_replace("/srv/www/violet/web/", "", $thumnail);
     74            } else {
     75                return "";
     76            }
     77        } else {
     78            return "";
     79        }
     80       
     81        return sfView::NONE;
     82    }
    4083}
Note: See TracChangeset for help on using the changeset viewer.