public function saveProfilePicture()
 {
     $twitterClient = new TwitterOAuth(Config::get('services.twitter.consumerKey'), Config::get('services.twitter.consumerSecret'), Config::get('services.twitter.accessToken'), Config::get('services.twitter.accessSecret'));
     // Fetch the URL of the user's profile picture
     $user = $twitterClient->get('users/show', ['screen_name' => $this->screen_name]);
     $profilePictureUrl = preg_replace("/_normal/", "", $user->profile_image_url);
     // Save it locally
     $profilePicture = file_get_contents($profilePictureUrl);
     create_if_does_not_exist(public_path('media/twitterprofiles'));
     file_put_contents(public_path('media/twitterprofiles/' . $this->screen_name . '.png'), $profilePicture);
 }
 private function createThumbnail($thumbnailType)
 {
     // Check if the directory exists, if not, create
     create_if_does_not_exist(public_path($this->directory[$thumbnailType]));
     // Open the file
     $image = new Imagick(public_path($this->directory['full'] . $this->fileinfo['filename']));
     // Set the thumbnail size
     $image->thumbnailImage($this->{$thumbnailType . 'ThumbnailSize'}, $this->{$thumbnailType . 'ThumbnailSize'}, true);
     // Create the relevant thumbnail
     $image->writeImage(public_path($this->directory[$thumbnailType] . $this->fileinfo['filename']));
 }
 public function saveFavicon()
 {
     $favicon = file_get_contents('http://www.google.com/s2/favicons?domain=' . $this->url);
     create_if_does_not_exist(public_path('media/publications'));
     file_put_contents(public_path('media/publications/' . $this->name . '.jpg'), $favicon);
 }
 /**
  * Makes a local copy of a file and thumbs for an object, preferentially fetching from the temporary storage
  * before trying to fetch from S3. Does not delete any temporary files if they exist,
  * call deleteFromTemporary() for this. Does not save file locations to the database, call save() for this.
  */
 public function putToLocal()
 {
     $s3 = AWS::createClient('s3');
     if ($this->hasFile()) {
         if ($this->hasTemporaryFile()) {
             create_if_does_not_exist(public_path('media/local/full'));
             copy(public_path('media/temporary/full/' . $this->filename), public_path('media/local/full/' . $this->filename));
         } else {
             if ($this->hasCloudFile()) {
                 $s3->getObject(array('Bucket' => Config::get('filesystems.disks.s3.bucket'), 'Key' => $this->filename, 'SaveAs' => public_path('media/local/' . $this->filename)));
             }
         }
         $this->has_local_file = true;
     }
     if ($this->hasThumbs()) {
         if ($this->hasTemporaryThumbs()) {
             create_if_does_not_exist(public_path('media/temporary/small/'));
             copy(public_path('media/temporary/small/' . $this->thumb_filename), public_path('media/local/small/' . $this->thumb_filename));
             create_if_does_not_exist(public_path('media/local/large/'));
             copy(public_path('media/temporary/large/' . $this->thumb_filename), public_path('media/local/large/' . $this->thumb_filename));
         } else {
             if ($this->hasCloudThumbs()) {
                 $s3->getObject(array('Bucket' => Config::get('filesystems.disks.s3.bucketLargeThumbs'), 'Key' => $this->thumb_filename, 'SaveAs' => public_path('media/local/large/' . $this->filename)));
                 $s3->getObject(array('Bucket' => Config::get('filesystems.disks.s3.bucketSmallThumbs'), 'Key' => $this->thumb_filename, 'SaveAs' => public_path('media/local/small/' . $this->filename)));
             }
         }
         $this->has_local_thumbs = true;
     }
     $this->reindex();
     return $this;
 }
 private function setThumbnails()
 {
     $thumbnailsToCreate = ['small', 'large'];
     // Set the point in the video to extract the frame at approximately 10% of the video length;
     $frameExtractionPoint = (int) round($this->getLength() / 10);
     // Open the video and extract a frame at 10% of the video's duration
     $video = $this->ffmpeg->open($this->directory['full'] . $this->fileinfo['filename']);
     $frame = $video->frame(TimeCode::fromSeconds($frameExtractionPoint));
     // Save frame to temporary location
     create_if_does_not_exist(public_path($this->directory['frames']));
     $frame->save($this->directory['frames'] . $this->fileinfo['filename_without_extension'] . '.jpg');
     foreach ($thumbnailsToCreate as $size) {
         $lengthDimension = $size == 'small' ? $this->smallThumbnailSize : $this->largeThumbnailSize;
         // create an Imagick instance
         $image = new \Imagick(public_path($this->directory['frames'] . $this->fileinfo['filename_without_extension'] . '.jpg'));
         $image->thumbnailImage($lengthDimension, $lengthDimension, true);
         create_if_does_not_exist(public_path($this->directory[$size]));
         $image->writeImage(public_path($this->directory[$size] . $this->fileinfo['filename_without_extension'] . '.jpg'));
     }
     // Delete the temporary frame
     unlink($this->directory['frames'] . $this->fileinfo['filename_without_extension'] . '.jpg');
 }