/** * Get a thumbnail image * * @param Media $media media instance * @param string $type thumbnail make type * @param string $dimension dimension code * @param bool $defaultSelf if set true, returns self when thumbnail not exists * @return null|Image|Media */ public function getThumbnail(Media $media, $type, $dimension, $defaultSelf = true) { $meta = $this->repo->findByOption(['originId' => $media->getFile()->getId(), 'type' => $type, 'code' => $dimension]); if ($meta !== null) { $file = $this->storage->get($meta->id); return $this->createModel($file, $meta); } return $defaultSelf === true ? $media : null; }
/** * 회원의 프로필 이미지를 등록한다. * * @param MemberEntityInterface $member 프로필 이미지를 등록할 회원 * @param UploadedFile $profileFile 프로필 이미지 파일 * * @return string 등록한 프로필이미지 ID */ public function updateMemberProfileImage(MemberEntityInterface $member, UploadedFile $profileFile) { $disk = array_get($this->profileImgConfig, 'storage.disk'); $path = array_get($this->profileImgConfig, 'storage.path'); $size = array_get($this->profileImgConfig, 'size'); // make fitted imageg /** @var ImageManager $imageManager */ $imageManager = call_user_func($this->imageManagerResolver); $image = $imageManager->make($profileFile->getRealPath()); $image = $image->fit($size['width'], $size['height']); // remove old profile image if ($member->profileImageId !== null && $member->profileImageId !== "") { $file = $this->storage->get($member->profileImageId); $this->storage->remove($file); } $id = $member->getId(); // save image to storage $file = $this->storage->create($image->encode()->getEncoded(), $path . "/{$id}", $id, $disk); return $file->getId(); }
public function file($id) { $file = $this->storage->get($id); header('Content-type: ' . $file->mime); echo $this->storage->read($file); }
public function testGet() { list($handler, $repo, $auth, $keygen) = $this->getMocks(); $mockFile = m::mock('Xpressengine\\Storage\\File'); $repo->shouldReceive('find')->once()->with('fileidstring')->andReturn($mockFile); $instance = new Storage($handler, $repo, $auth, $keygen); $file = $instance->get('fileidstring'); $this->assertInstanceOf('Xpressengine\\Storage\\File', $file); }