Esempio n. 1
0
 public function cropImgAction(Request $request)
 {
     $options = $request->request->all();
     if (empty($options['group'])) {
         $options['group'] = "default";
     }
     if (!$this->isGroup($options['group'])) {
         return $this->createMessageResponse("error", "参数不正确");
     }
     $fileId = $request->getSession()->get("fileId");
     if (empty($fileId)) {
         return $this->createMessageResponse("error", "参数不正确");
     }
     $record = $this->getFileService()->getFile($fileId);
     if (empty($record)) {
         return $this->createMessageResponse("error", "文件不存在");
     }
     $parsed = $this->getFileService()->parseFileUri($record['uri']);
     $filePaths = FileToolKit::cropImages($parsed["fullpath"], $options);
     $fields = array();
     foreach ($filePaths as $key => $value) {
         $file = $this->getFileService()->uploadFile($options["group"], new File($value));
         $fields[] = array("type" => $key, "id" => $file['id']);
     }
     if (isset($options["deleteOriginFile"]) && $options["deleteOriginFile"] == 0) {
         $fields[] = array("type" => "origin", "id" => $record['id']);
     } else {
         $this->getFileService()->deleteFileByUri($record["uri"]);
     }
     return $this->createJsonResponse($fields);
 }
Esempio n. 2
0
 public function avatarFetchPartnerAction(Request $request)
 {
     $currentUser = $this->getCurrentUser();
     if (!$this->getAuthService()->hasPartnerAuth()) {
         throw $this->createNotFoundException();
     }
     $url = $this->getAuthService()->getPartnerAvatar($currentUser['id'], 'big');
     if (empty($url)) {
         $this->setFlashMessage('danger', '获取论坛头像地址失败!');
         return $this->createJsonResponse(true);
     }
     $avatar = $this->fetchAvatar($url);
     if (empty($avatar)) {
         $this->setFlashMessage('danger', '获取论坛头像失败或超时,请重试!');
         return $this->createJsonResponse(true);
     }
     $imgUrl = $request->request->get('imgUrl');
     $file = new File($this->downloadImg($imgUrl));
     $groupCode = "tmp";
     $imgs = array('large' => array("200", "200"), 'medium' => array("120", "120"), 'small' => array("48", "48"));
     $options = array('x' => "0", 'y' => "0", 'x2' => "200", 'y2' => "200", 'w' => "200", 'h' => "200", 'width' => "200", 'height' => "200", 'imgs' => $imgs);
     if (empty($options['group'])) {
         $options['group'] = "default";
     }
     $record = $this->getFileService()->uploadFile($groupCode, $file);
     $parsed = $this->getFileService()->parseFileUri($record['uri']);
     $filePaths = FileToolKit::cropImages($parsed["fullpath"], $options);
     $fields = array();
     foreach ($filePaths as $key => $value) {
         $file = $this->getFileService()->uploadFile($options["group"], new File($value));
         $fields[] = array("type" => $key, "id" => $file['id']);
     }
     if (isset($options["deleteOriginFile"]) && $options["deleteOriginFile"] == 0) {
         $fields[] = array("type" => "origin", "id" => $record['id']);
     } else {
         $this->getFileService()->deleteFileByUri($record["uri"]);
     }
     $this->getUserService()->changeAvatar($currentUser["id"], $fields);
     return $this->createJsonResponse(true);
 }
Esempio n. 3
0
    $options['h'] = $request->request->get('x', 180);
    $options['width'] = $imgInfo[0];
    $options['height'] = $imgInfo[1];
    $imgs = array();
    $large = array(200, 200);
    $imgs['large'] = $large;
    $medium = array(120, 120);
    $imgs['medium'] = $medium;
    $small = array(48, 48);
    $imgs['small'] = $small;
    $options['imgs'] = $imgs;
    $options['group'] = $groupCode;
    if (empty($options['group'])) {
        $options['group'] = "default";
    }
    $filePaths = FileToolKit::cropImages($parsed["fullpath"], $options);
    $fields = array();
    foreach ($filePaths as $key => $value) {
        $file = $FileService->uploadFile($options["group"], new File($value));
        $fields[] = array("type" => $key, "id" => $file['id']);
    }
    if (isset($options["deleteOriginFile"]) && $options["deleteOriginFile"] == 0) {
        $fields[] = array("type" => "origin", "id" => $record['id']);
    } else {
        $FileService->deleteFileByUri($record["uri"]);
    }
    //保存图片地址到个人信息
    $UserService = ServiceKernel::instance()->createService('User.UserService');
    $user = $UserService->changeAvatar($userId, $fields);
    return $user;
});
Esempio n. 4
0
 private function updateUserAvatar($user, $fileId)
 {
     if (empty($fileId)) {
         return;
     }
     list($pictureUrl, $naturalSize, $scaledSize) = $this->getFileService()->getImgFileMetaInfo($fileId, 270, 270);
     $options = $this->createImgCropOptions($naturalSize, $scaledSize);
     $record = $this->getFileService()->getFile($fileId);
     if (empty($record)) {
         throw new \RuntimeException("Error file not exists");
     }
     $parsed = $this->getFileService()->parseFileUri($record['uri']);
     $filePaths = FileToolKit::cropImages($parsed["fullpath"], $options);
     $fields = array();
     foreach ($filePaths as $key => $value) {
         $file = $this->getFileService()->uploadFile("user", new File($value));
         $fields[] = array("type" => $key, "id" => $file['id']);
     }
     if (isset($options["deleteOriginFile"]) && $options["deleteOriginFile"] == 0) {
         $fields[] = array("type" => "origin", "id" => $record['id']);
     } else {
         $this->getFileService()->deleteFileByUri($record["uri"]);
     }
     if (empty($fields)) {
         throw new \RuntimeException("Error uplaod avatar");
     }
     $this->getUserService()->changeAvatar($user['id'], $fields);
 }