Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function compress_image(){
- if($_POST['image']){
- //Lấy đường dẫn hình
- $img = $_POST['image'];
- $path = $this->img_cfg['root_path'];
- $mCfg = null;
- //Cắt đường dẫn hình
- $imgExp = explode("/", $img);
- //Nếu không rỗng thì tiến hành lấy folder là avatars hoặc shares
- if(!empty($imgExp)){
- $objImg = new Imagick($path.$img);
- if(strtolower($imgExp[1]) == 'avatars'){
- $mCfg = $this->img_cfg['size']['avatar'];
- } elseif(strtolower($imgExp[1]) == 'shares'){
- $mCfg = $this->img_cfg['size']['share'];
- }
- $mCfg= array_reverse($mCfg);
- foreach ($mCfg as $key => $value) {
- $oSize = explode(",", $value);
- $w = $oSize[0];
- $h = $oSize[1];
- $nName = $key.'_'.$imgExp[3];
- $objImg->resizeImage($w, $h, Imagick::IMGTYPE_TRUECOLOR , 1);
- $objImg->thumbnailImage($w, $h);
- $objImg->setImageCompressionQuality(100);
- $newPath = $path.$imgExp[0].'/'.$imgExp[1].'/'.$imgExp[2].'/'.$nName;
- $objImg->writeImageFile(fopen($newPath, "wb"));
- //$objImg = new Imagick($newPath);
- }
- $objImg->destroy();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment