在PHP中降低图像质量

时间:2017-04-20 07:53:12

标签: php laravel laravel-5 laravel-5.2

如何使用PHP降低图像质量?

upload_mode = @$this->setting->upload_mode?:'file';
            $upload_path = @$this->setting->upload_path?:'uploads/';

            $file               = Request::file($name);
            $fm                 = array();
            $fm['name']         = $_FILES[$name]['name'];                   
            $fm['ext']          = $file->getClientOriginalExtension();
            $fm['size']         = $_FILES[$name]['size'];
            $fm['content_type'] = $_FILES[$name]['type'];

            if($upload_mode=='database') {
                $fm['filedata']     = file_get_contents($_FILES[$name]['tmp_name']);
                DB::table('cms_filemanager')->insert($fm);
                $id_fm              = DB::getPdo()->lastInsertId();
                DB::table('cms_filemanager')->where('id',$id_fm)->update(['id_md5' =>md5($id_fm)]);
                $filename           = 'upload_virtual/files/'.md5($id_fm).'.'.$fm['ext'];
            }else{
                if(!file_exists($upload_path.date('Y-m'))) {
                    if(!mkdir($upload_path.date('Y-m'),0777)) {
                        die('Gagal buat folder '.$upload_path.date('Y-m'));
                    }
                }
                $filename = md5(str_random(12)).'.'.$fm['ext'];
                $file->move($upload_path.date('Y-m'),$filename);                        
                $filename = $upload_path.date('Y-m').'/'.$filename;
            }

            $url                = asset($filename);
有人帮帮我吗?我需要添加什么使它像我需要的那样工作?

1 个答案:

答案 0 :(得分:1)

  

GD是一个用于动态创建图像的开源代码库   由程序员。 GD是用C语言编写的,“包装器”可用   Perl,PHP和其他语言。 GD创建PNG,JPEG和GIF图像,   等格式。 GD通常用于生成图表,图形,   缩略图,以及大多数其他东西,在飞行中。

减少图像文件大小的代码:

(module "\00asm\01\00\00\00")
(module "\00asm" "\01\00\00\00")
(module $M1 "\00asm\01\00\00\00")
(module $M2 "\00asm" "\01\00\00\00")

(assert_malformed (module "") "unexpected end")
(assert_malformed (module "\01") "unexpected end")

Reference