/** * 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'); }
/** * @param \Agency\Media\Photos\UploadedPhoto $original * @param $small_dimensions * @param $thumb_dimensions * @param $square_dimensions * * @return array */ public function resize(UploadedPhoto $original, $small_dimensions, $thumb_dimensions, $square_dimensions) { /** * @todo Handle exceptions and delete cached files when they occur. */ // store the resized stuff here $resized = []; // trash: hold all the file paths that needs to be removed from filesystem (unliked) $trash = []; // extract photo data $file = $original->file(); $file_name = $original->name(); $file_path = $original->path(); $file_extention = $original->extension(); $mime = $original->mime(); $original_width = $original->width(); $original_height = $original->height(); $crop_width = $original->cropWidth(); $crop_height = $original->cropHeight(); $crop_x = $original->cropX(); $crop_y = $original->cropY(); $name = $this->nameFile($file_name, $file_extention); $original_photo = $this->editor->makePhoto($file_path); $original_photo->name = $file_name; $original_path = $this->editor->cache($original_photo); $trash[] = $original_path; // set original photo $resized['original'] = ['name' => $name, 'file' => $original_photo, 'mime' => $mime]; // determine whether this is a landscape or portrait image $orientation = $this->editor->orientation($original_width, $original_height); if ($orientation === 'landscape') { $small_width = $small_dimensions['width']; $small_height = $original_height; } else { $small_width = $original_width; $small_height = $small_dimensions['height']; } // generate the small photo $small_name = $this->nameFile($name, $file_extention, 'small', true); $small = $this->editor->scale($file_path, $small_width, $small_height); $small_path = $this->editor->cache($small); $trash[] = $small_path; // set the edited file's name $small->name = $file_name; $resized['small'] = ['file' => $small, 'name' => $small_name, 'mime' => $mime]; // crop photo according to the cropping dimensions // to get a 3/2 aspect ratio $cropped = $this->editor->crop($file_path, $crop_width, $crop_height, $crop_x, $crop_y); // cache the generated crop $cropped_path = $this->editor->cache($cropped); $trash[] = $cropped_path; // generate thumbnail $thumb_name = $this->nameFile($name, $file_extention, 'thumb', true); $thumb = $this->editor->resize($cropped_path, $thumb_dimensions['width'], $thumb_dimensions['height']); // set the edited file's name $thumb->name = $file_name; // cache the generated thumbnail $thumb_path = $this->editor->cache($thumb); $trash[] = $thumb_path; // set thumbnail photo $resized['thumbnail'] = ['name' => $thumb_name, 'file' => $thumb, 'mime' => $mime]; // generate square $square_name = $this->nameFile($name, $file_extention, 'sq', true); $square = $this->editor->crop($thumb_path, $square_dimensions['width'], $square_dimensions['height'], $crop_x = 50); $square->name = $file_name; $square_path = $this->editor->cache($square); $trash[] = $square_path; $resized['square'] = ['name' => $square_name, 'file' => $square, 'mime' => $mime]; // remove cached files array_map(function ($path) { @unlink($path); }, $trash); return $resized; }
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); }