/** * upload to AWS * * @param $file * @param $meta * @param $crop * * @return bool */ private function aws($file, $meta, $crop) { $uploadedFile = new UploadedFile($file, $file); // prepare the crop data for the UploadedPhoto class $crop_data = ['width' => $meta['width'], 'height' => $meta['height'], 'crop_width' => $crop['width'], 'crop_height' => $crop['height'], 'crop_x' => $crop['x'], 'crop_y' => $crop['y']]; // instantiate a photos collection $photos = new UploadedPhotosCollection(); $photo = UploadedPhoto::make($uploadedFile, $crop_data); $photos->push($photo); // upload to 'photos' directory return $this->photo_manager->upload($photos, 'photos'); }
/** * Upload a collection of photos. * * @param Agency\Media\Photos\UploadedPhotosCollection $photo * @return void */ public function upload(UploadedPhotosCollection $photos, $directory) { $config = $this->config->get('media.photos'); $small_dimensions = $config['presets']['small']; $square_dimensions = $config['presets']['square']; $thumbnail_dimensions = $config['presets']['thumbnail']; // holds the resized images // to be passed to the uploader later on $resized = []; foreach ($photos->toArray() as $original) { $processed = $this->resize($original, $small_dimensions, $thumbnail_dimensions, $square_dimensions); array_push($resized, $processed); } return $this->uploadPhotos($resized, $directory); }
public function save($post_id = null) { $related_models = []; $related_models['admin'] = Auth::getUser(); $tags = Input::get('tags'); $tags_id = $this->addTags($tags, $post_id); if (!is_null($tags_id)) { $related_models['tags'] = $tags_id; } $photos = new UploadedPhotosCollection(); // upload images if (Input::has('croped_images_array')) { $crop_sizes = json_decode(Input::get('croped_images_array')); if (Input::has('images')) { $images = Input::get('images'); foreach ($images as $key => $image) { $image = new UploadedFile(public_path() . "/" . Config::get("media.location") . "/" . $image, $image); $crop_size = get_object_vars($crop_sizes[$key]); $photo = UploadedPhoto::make($image, $crop_size)->validate(); $photos->push($photo); } $response = $this->manager->upload($photos, 'artists/webs'); $response = $response->toArray(); $images = $this->filter_response->make($response); $related_models['images'] = $images['originals']; } } $photos = new UploadedPhotosCollection(); if (Input::has('cover')) { $cover_crop_size = json_decode(Input::get('croped_cover')); if (!is_null($cover_crop_size)) { $cover = Input::get('cover'); $cover = new UploadedFile(public_path() . $cover, $cover); $cover_crop_size = get_object_vars($cover_crop_size); $cover = UploadedPhoto::make($cover, $cover_crop_size)->validate(); $photos->push($cover); $response = $this->manager->upload($photos, 'artists/webs'); $response = $response->toArray(); $images = $this->filter_response->make($response); $related_models['coverImage'] = $images['originals']; } } $videos = json_decode(Input::get('videos')); if (sizeof($videos) > 0) { $videos = $this->parser_interface->make($videos); $related_models['videos'] = $videos; } return $related_models; }
public function save($post_id) { //detach all tags $this->posts->detachTags($post_id); $tags = explode(', ', Input::get('tags')); // filter empty tags $tags = array_filter($tags); if (!empty($tags)) { // get tags ids $tags = $this->tags->splitFound($tags); // add new tags to post $new_tags = $this->posts->addTags($post_id, $tags['new'], $tags['existing']); } // upload images if (Input::has('croped_images_array')) { $photos = new UploadedPhotosCollection(); $crop_sizes = json_decode(Input::get('croped_images_array')); if (Input::has('images')) { $images = Input::get('images'); foreach ($images as $key => $image) { $image = new UploadedFile(public_path() . "/tmp/{$image}", $image); $crop_size = get_object_vars($crop_sizes[$key]); $photo = UploadedPhoto::make($image, $crop_size)->validate(); $photos->push($photo); } $response = $this->manager->upload($photos, 'artists/webs'); $response = $response->toArray(); $images = $this->filter_response->make($response); $this->images->store($images['without_original']); $this->posts->addImages($post_id, $images['originals']); } } $videos = json_decode(Input::get('videos')); $videos = $this->parser_interface->make($videos); $this->posts->addVideos($post_id, $videos); }