Ejemplo n.º 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;
 }