public function rotate($jobget, $pid = 0, $direction = 1, $is_step = TRUE) { list($pid, $direction) = $this->_jobInit($jobget, $pid, $direction); $photoModel = new Photo(); if (!$photoModel->findOne($pid)) { //获取原图信息 return $this->_jobResult(FALSE); } if (!$is_step) { $photoModel->direction = $direction; } else { $photoModel->direction += $direction; if ($photoModel->direction >= 4) { $photoModel->direction = 0; } if ($photoModel->direction < 0) { $photoModel->direction = 3; } } //判断是否存在 $this->thumb_source = $photoModel->getSource(); if (!$this->thumb_source) { $raw = (array) $photoModel; $raw['direction'] = 0; $originSource = $photoModel->getRawSource($raw); if ($originSource && ($tmp_file = $originSource->downBuffer())) { $angle = $photoModel->direction * 90; $imagine = new Imagine\Imagick\Imagine(); $image = $imagine->open($tmp_file); $thumb_file = $tmp_file . '.jpg'; $image->rotate($angle)->save($thumb_file, array('quality' => Core::config('photo_quality'))); @unlink($tmp_file); $this->uploader = new Uploader(); $this->uploader->process($thumb_file); //原图属性 $updata['fmime'] = $photoModel->mime; $updata['flength'] = $photoModel->size; $updata['fmd5'] = $photoModel->md5; $updata['direction'] = $photoModel->direction; //缩略图属性 $updata['mime'] = $this->uploader->getMIME(); $updata['meta'] = FALSE; //缩略图不需要meta信息 $photoinfo = $this->uploader->getInfo(); $updata['width'] = $photoinfo['width']; $updata['height'] = $photoinfo['height']; if ($this->uploader->getType() !== Uploader::FILETYPE_IMAGE) { return $this->_jobResult(FALSE); } if ($originSource->upBuffer($this->uploader->tmpfile, $updata)) { $this->thumb_source = $originSource; } } } if ($this->thumb_source) { $row['width'] = $this->thumb_source->width; $row['height'] = $this->thumb_source->height; $row['direction'] = $photoModel->direction; $row['mtime'] = time(); $photoModel->update($row); return $this->_jobResult(TRUE); } return $this->_jobResult(FALSE); }
public function geturiByMD5($md5_arr, $self = FALSE) { $r = array(); if (!$md5_arr) { return $r; } if (!is_array($md5_arr)) { $md5_arr = array($md5_arr); } $md5_arr = array_map('strtolower', $md5_arr); //构建sql查询语句 $sql = "SELECT `fid`,`md5`,`path`,`mime`,`thumb_id` FROM `fs_fileentry` WHERE 0 "; foreach ($md5_arr as $md5) { $sql .= "OR (`md5`='{$md5}'" . ($self ? " AND `uid`=" . Core::getUserID() : "") . ") "; } $this->connectDB(); $query = self::$db->query($sql); $result = array(); while ($row = self::$db->fetchArray($query)) { $md5 = $row['md5']; $id = intval($row['fid']); $thumb_id = intval($row['thumb_id']); $result[$md5] = array('id' => $id, 'src' => $this->geturi($id), 'mime' => $row['mime'], 'name' => $row['name']); if ($thumb_id) { $photoModel = new Photo(); if ($photoModel->findOne($thumb_id)) { $result[$md5]['thumb']['id'] = $photoModel->get_pid(); $result[$md5]['thumb']['mime'] = $photoModel->mime; $imgurls = $photoModel->geturi($thumb_id, 130); $result[$md5]['thumb']['src'] = $imgurls[0]; } } } foreach ($md5_arr as $md5) { $r[] = $result[$md5] ? $result[$md5] : array('id' => 0, 'src' => ''); } return $r; }