Beispiel #1
0
 public function saveThumb($thumb)
 {
     $root = Config::get('consts.note_root');
     $time = time();
     ImageService::savePic($root . 'thumb/', $this, $thumb, 'thumb', false, $time, 400, 300);
     $this->save();
 }
Beispiel #2
0
 public function saveThumbs($thumb, $banner)
 {
     $root = Config::get('consts.product_root');
     $time = time();
     ImageService::savePic($root . 'thumb/', $this, $thumb, 'thumb', true, $time, 600, 338);
     ImageService::savePic($root . 'banner/', $this, $banner, 'banner', true, $time, 1200, 400);
 }
Beispiel #3
0
 public static function saveImage($banner, $file)
 {
     $root = Config::get('consts.banner_root');
     $uname = time();
     ImageService::savePic($root, $banner, $file, 'path', false, $uname, 0, 0);
     list($width, $height) = getimagesize($banner->path);
     $banner->width = $width;
     $banner->height = $height;
     $banner->save();
 }
 static function createPhoto($activity, $photo)
 {
     $activityPhoto = new ActivityPhoto();
     $activityPhoto->product_id = $activity->product_id;
     $activityPhoto->activity_id = $activity->id;
     $root = Config::get('consts.activity_root') . $activity->id . '/';
     $time = time() . str_random(10);
     $thumbName = $root . $time . '_thumb.jpg';
     ImageService::savePic($root, $activityPhoto, $photo, 'photo', false, $time, 1200, 900);
     ImageService::createThumb($activityPhoto->photo, $activityPhoto, 'thumb', false, $thumbName, 400, 300);
     $activityPhoto->save();
 }
 /**
  * @param array $conf
  * @param string $ext
  * @param int $categoryType
  * @param int $categorySubType
  * @param string $path
  * @param string $mediaType
  * @param array $metaInputs
  * @return \App\Models\Base|null
  */
 private function uploadImage($conf, $ext, $categoryType, $categorySubType, $path, $mediaType, $metaInputs)
 {
     $dstPath = $path . '.converted';
     $format = array_get($conf, 'format', 'jpeg');
     $size = $this->imageService->convert($path, $dstPath, $format, array_get($conf, 'size'));
     if (!file_exists($dstPath)) {
         return null;
     }
     $fileSize = filesize($path);
     $bucket = $this->decideBucket($conf['buckets']);
     $region = array_get($conf, 'region', 'ap-northeast-1');
     $seed = array_get($conf, 'seed_prefix', '') . time() . rand();
     $key = $this->generateFileName($seed, null, $ext);
     $url = $this->uploadToS3($dstPath, $region, $bucket, $key, 'image/' . $format);
     $image = $this->imageRepository->create(['url' => $url, 'title' => array_get($metaInputs, 'title', ''), 'file_category' => $categoryType, 'file_subcategory' => $categorySubType, 'article_id' => array_get($metaInputs, 'articleId', ''), 's3_key' => $key, 's3_bucket' => $bucket, 's3_region' => $region, 's3_extension' => $ext, 'media_type' => $mediaType, 'format' => $mediaType, 'file_size' => $fileSize, 'width' => array_get($size, 'width', 0), 'height' => array_get($size, 'height', 0), 'is_enabled' => true]);
     foreach (array_get($conf, 'thumbnails', []) as $thumbnail) {
         $this->imageService->convert($path, $dstPath, $format, $thumbnail);
         $thumbnailKey = $this->getThumbnailKeyFromKey($key, $thumbnail);
         $this->uploadToS3($dstPath, $region, $bucket, $thumbnailKey, 'image/' . $format);
     }
     return $image;
 }
 /**
  * Update the specified user in storage.
  *
  * @param User $user
  * @param UserRequest $request
  * @return Response
  */
 public function update(User $user, UserRequest $request)
 {
     $user->fill(ImageService::uploadImage($request, 'picture'));
     $user->save() ? Flash::success(trans('admin.update.success')) : Flash::error(trans('admin.update.fail'));
     return redirect(route('admin.user.index'));
 }
Beispiel #7
0
 /**
  * Update the specified language in storage.
  *
  * @param Language $language
  * @param LanguageRequest $request
  * @return Response
  */
 public function update(Language $language, LanguageRequest $request)
 {
     $language->fill(ImageService::uploadImage($request, 'flag'));
     $language->save() ? Flash::success(trans('admin.update.success')) : Flash::error(trans('admin.update.fail'));
     return redirect(route('admin.language.index'));
 }
 /**
  * Update the settings in storage.
  *
  * @param Setting $setting
  * @param SettingRequest $request
  * @return Response
  */
 public function patchSettings(Setting $setting, SettingRequest $request)
 {
     $setting->fill(ImageService::uploadImage($request, 'logo'));
     $setting->save() ? Flash::success(trans('admin.update.success')) : Flash::error(trans('admin.update.fail'));
     return redirect(route('admin.setting.index'));
 }