Beispiel #1
0
 /**
  * Creates the necessary images to be used as an avatar.
  *
  * @since	1.0
  * @access	public
  * @param	string		The target location to store the avatars
  * @param	Array		An array of excluded sizes.
  * @return
  */
 public function create($path, $exclusion = array(), $overrideFileName = '')
 {
     // Files array store a list of files
     // created for this photo.
     $files = array();
     // Create stock image
     $filename = $this->generateFilename('stock', $overrideFileName);
     $file = $path . '/' . $filename;
     $files['stock'] = $filename;
     $this->image->copy(JPATH_ROOT . $path . '/' . $filename);
     // Create original image
     $filename = $this->generateFilename('original');
     $file = JPATH_ROOT . $path . '/' . $filename;
     $files['original'] = $filename;
     $this->image->rotate(0);
     // Fake an operation queue
     $this->image->save($file);
     // Use original image as source image
     // for all other image sizes.
     $sourceImage = FD::image()->load($file);
     // Create the rest of the image sizes
     foreach (self::$sizes as $name => $size) {
         if (in_array($name, $exclusion)) {
             continue;
         }
         // Clone an instance of the source image.
         // Otherwise subsequent resizing operations
         // in this loop would end up using the image
         // instance that was resized by the previous loop.
         $image = $sourceImage->cloneImage();
         $filename = $this->generateFilename($name, $overrideFileName);
         $file = JPATH_ROOT . $path . '/' . $filename;
         $files[$name] = $filename;
         // Resize image
         $method = $size['mode'];
         $image->{$method}($size['width'], $size['height']);
         // Save image
         $image->save($file);
         // Free up memory
         unset($image);
     }
     return $files;
 }
Beispiel #2
0
 /**
  * Creates the necessary images to be used as an avatar.
  *
  * @since	1.0
  * @access	public
  * @param	string		The target location to store the avatars
  * @return
  */
 public function create(&$avatarTable = null, $options = array())
 {
     // Get a list of files to build.
     $names = $this->generateFileNames();
     if (is_string($avatarTable)) {
         $targetLocation = $avatarTable;
     } else {
         $targetLocation = !empty($targetLocation) ? $targetLocation : $this->getPath();
     }
     foreach ($names as $size => $name) {
         $info = self::${$size};
         $image = $this->image->cloneImage();
         if ($info['mode'] == 'fill') {
             $image->fill($info['width'], $info['height']);
         }
         if ($info['mode'] == 'resize') {
             $image->resize($info['width'], $info['height']);
         }
         if ($info['mode'] == 'proportionate') {
             $image->width($info['width']);
         }
         $path = $targetLocation . '/' . $name;
         if (JFile::exists($path)) {
             JFile::delete($path);
         }
         $image->save($path);
         if ($avatarTable instanceof SocialTableAvatar) {
             $avatarTable->{$size} = $name;
         }
     }
     // Delete the tmp path once it's saved
     // Don't delete if options['deleteimage'] is specifically set to false
     if (!isset($options['deleteimage']) || $options['deleteimage'] != false) {
         $tmp = $image->getPath();
         if ($tmp) {
             JFile::delete($tmp);
         }
     }
     return $names;
 }
Beispiel #3
0
 /**
  * Processes rules after storing an image
  *
  * @since   1.2
  * @access  public
  * @param   string
  * @return
  */
 public function afterStore($file, SocialImage $image)
 {
     // Load up exif library
     $exif = FD::get('Exif');
     // Push all the ordering of the photo down
     $model = FD::model('Photos');
     $model->pushPhotosOrdering($this->album_id, $this->id);
     // Detect location for the photo
     if ($exif->isAvailable() && $image->hasExifSupport()) {
         // Load the file
         $exif->load($file['tmp_name']);
         // Get the location
         $locationCoordinates = $exif->getLocation();
         // Once we have the coordinates, we need to reverse geocode it to get the address.
         if ($locationCoordinates) {
             $my = FD::user();
             $geocode = FD::get('GeoCode');
             $address = $geocode->reverse($locationCoordinates->latitude, $locationCoordinates->longitude);
             $location = FD::table('Location');
             $location->loadByType($this->id, SOCIAL_TYPE_PHOTO, $my->id);
             $location->address = $address;
             $location->latitude = $locationCoordinates->latitude;
             $location->longitude = $locationCoordinates->longitude;
             $location->user_id = $my->id;
             $location->type = SOCIAL_TYPE_PHOTO;
             $location->uid = $this->id;
             $state = $location->store();
         }
         // Store custom meta data for the photo
         $model->storeCustomMeta($this, $exif);
     }
     // Synchronize with our search index
     $indexer = FD::get('Indexer');
     $template = $indexer->getTemplate();
     $template->setContent($this->title, $this->caption);
     // Get the url for the photo
     // $url     = FRoute::photos( array( 'layout' => 'item', 'id' => $this->getAlias() ) );
     $url = $this->getPermalink();
     $template->setSource($this->id, SOCIAL_INDEXER_TYPE_PHOTOS, $this->uid, $url);
     $template->setThumbnail($this->getSource('thumbnail'));
     $indexer->index($template);
 }
Beispiel #4
0
 /**
  * Generates a random image name based on the node id.
  *
  * Example:
  * <code>
  * <?php
  * $avatar 	= FD::get( 'Avatar' );
  *
  * // Returns md5 hash.
  * $output	= $avatar->generateName( 'anyprefix' , 'anysuffix' , '.png' );
  *
  * @since	1.0
  * @access	public
  * @param	string	Prefix for the file name.
  * @param	string	Suffix for the file name.
  * @param	string	The extension of the file.
  */
 public function getUniqueName()
 {
     $name = md5($this->image->getName() . uniqid());
     return $name;
 }