Linux下使用convert实现图片缩放和使用mencoder进行

来源:互联网 发布:鸿鹊 知乎 编辑:程序博客网 时间:2024/06/08 08:12

鉴于工作需要,研究了一下Linux的convert命令和mencoder命令

一、使用convert命令实现图片缩放

工作需求:在用户上传图片时进行异步处理,生成一张中等比例的图片和一张小的缩略图。最终的结果,存储一张原图,一张中等比例的图片,一张缩略图。

上传图片使用百度的在线编辑器ueditor。对其上传类Uploader.class.php进行修改,具体操作如下

/*** 上传文件的主处理方法* @return mixed*/private function upFile() {$file = $this->file = $_FILES[$this->fileField];if (!$file) {    $this->stateInfo = $this->getStateInfo("ERROR_FILE_NOT_FOUND");    return;}if ($this->file['error']) {#error_log(json_encode($file), 3, "./logs/error.log");#error_log(json_encode($this->file), 3, "./logs/error.log");    $this->stateInfo = $this->getStateInfo($file['error']);    return;} else if (!file_exists($file['tmp_name'])) {    $this->stateInfo = $this->getStateInfo("ERROR_TMP_FILE_NOT_FOUND");    return;} else if (!is_uploaded_file($file['tmp_name'])) {    $this->stateInfo = $this->getStateInfo("ERROR_TMPFILE");    return;}$this->oriName = $file['name'];$this->fileSize = $file['size'];$this->fileType = $this->getFileExt();$this->fullName = $this->getFullName();$this->filePath = $this->getFilePath();$this->fileName = $this->getFileName();$dirname = dirname($this->filePath);//检查文件大小是否超出限制if (!$this->checkSize("upFile")) {    $this->stateInfo = $this->getStateInfo("ERROR_SIZE_EXCEED");    return;}//检查是否不允许的文件格式if (!$this->checkType()) {    $this->stateInfo = $this->getStateInfo("ERROR_TYPE_NOT_ALLOWED");    return;}//创建目录失败if (!file_exists($dirname) && !mkdir($dirname, 0777, true)) {    $this->stateInfo = $this->getStateInfo("ERROR_CREATE_DIR");    return;} else if (!is_writeable($dirname)) {    $this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE");    return;}//移动文件//if (!(move_uploaded_file($file["tmp_name"], $this->filePath) && file_exists($this->filePath))) { //移动失败$tmp_content = file_get_contents($file["tmp_name"]);$newfile = $this->_compress($tmp_content);if (!(file_put_contents($this->filePath, $newfile) && file_exists($this->filePath))) { //移动失败    $this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE");} else { //移动成功    //异步处理上传图片文件    if(in_array($this->fileType,array('.png','.jpg','.jpeg','.bmp'))){$getSize=getimagesize($this->filePath);$middleSize=$getSize[1] * (750 / $getSize[0]);$smallSize=$getSize[1] * (360 / $getSize[0]);$srcName=basename($this->fullName);$cmd = "sh ../shell/deal.sh $srcName $middleSize $smallSize >>logs/syn_upload.log  &";exec($cmd);    }    $this->stateInfo = $this->stateMap['SUCCESS'];}}
 
原创粉丝点击