src/libraries/models/Photo.php
/**
    * Generate a version of the photo as specified by the width, height and options.
    * This method requres the $hash ve validated to keep random versions of images to be created.
    * The photo is generated, uploaded to the remote file system and added to the database.
    * Operations are done in place on a downloaded version of the base photo and this file name is returned.
    *
    * @param string $id The id of the photo.
    * @param int $width The width of the requested photo.
    * @param int $height The height of the requested photo.
    * @param string $options Optional options to be applied on the photo
    * @return mixed string on success, false on failure
    */
Generate a version of the photo as specified by the width, height and options.
This method requres the $hash ve validated to keep random versions of images to be created.
The photo is generated, uploaded to the remote file system and added to the database.
Operations are done in place on a downloaded version of the base photo and this file name is returned.

@param string $id The id of the photo.
@param int $width The width of the requested photo.
@param int $height The height of the requested photo.
@param string $options Optional options to be applied on the photo
@return mixed string on success, false on failure
Generate a version of the photo as specified by the width height and options . This method requres the $hash ve validated to keep random versions of images to be created . The photo is generated uploaded to the remote file system and added to the database . Operations are done in place on a downloaded version of the base photo and this file name is returned . @param string $id The id of the photo . @param int $width The width of the requested photo . @param int $height The height of the requested photo . @param string $options Optional options to be applied on the photo @return mixed string on success false on failure
public function generate($id, $hash, $width, $height, $options = null)
  {
    if(!$this->isValidHash($hash, $id, $width, $height, $options))
      return false;
    $photo = $this->db->getPhoto($id);
    if(!$photo)
    {
      $this->logger->crit('Could not get photo from db in generate method');
      return false;
    }
    $filename = $this->fs->getPhoto($photo['pathBase']);
    if(!$filename)
    {
      $this->logger->crit('Could not get photo from fs in generate method');
      return false;
    }
    try
    {
      $this->image->load($filename);
    }
    catch(OPInvalidImageException $e)
    {
      $this->logger->crit('Could not get image from image adapter in generate method', $e);
      return false;
    }
    $maintainAspectRatio = true;
    if(!empty($options))
    {
      $optionsArray = (array)explode('x', $options);
      foreach($optionsArray as $option)
      {
        switch($option)
        {
          case 'BW':
            $this->image->greyscale();
            break;
          case 'CR':
            $maintainAspectRatio = false;
            break;
        }
      }
    }
    $this->image->scale($width, $height, $maintainAspectRatio);
    $this->image->write($filename);
    $customPath = $this->generateCustomUrl($photo['pathBase'], $width, $height, $options);
    $key = $this->generateCustomKey($width, $height, $options);
    $resFs = $this->fs->putPhoto($filename, $customPath);
    $resDb = $this->db->postPhoto($id, array($key => $customPath));
    if($resFs && $resDb)
      return $filename;
    return false;
  }
public function generate ( $ id , $ hash , $ width , $ height , $ options = null ) { if ( ! $ this -> isValidHash ( $ hash , $ id , $ width , $ height , $ options ) ) return false ; $ photo = $ this -> db -> getPhoto ( $ id ) ; if ( ! $ photo ) { $ this -> logger -> crit ( 'Could not get photo from db in generate method' ) ; return false ; } $ filename = $ this -> fs -> getPhoto ( $ photo [ 'pathBase' ] ) ; if ( ! $ filename ) { $ this -> logger -> crit ( 'Could not get photo from fs in generate method' ) ; return false ; } try { $ this -> image -> load ( $ filename ) ; } catch ( OPInvalidImageException $ e ) { $ this -> logger -> crit ( 'Could not get image from image adapter in generate method' , $ e ) ; return false ; } $ maintainAspectRatio = true ; if ( ! empty ( $ options ) ) { $ optionsArray = ( array ) explode ( 'x' , $ options ) ; foreach ( $ optionsArray as $ option ) { switch ( $ option ) { case 'BW' : $ this -> image -> greyscale ( ) ; break ; case 'CR' : $ maintainAspectRatio = false ; break ; } } } $ this -> image -> scale ( $ width , $ height , $ maintainAspectRatio ) ; $ this -> image -> write ( $ filename ) ; $ customPath = $ this -> generateCustomUrl ( $ photo [ 'pathBase' ] , $ width , $ height , $ options ) ; $ key = $ this -> generateCustomKey ( $ width , $ height , $ options ) ; $ resFs = $ this -> fs -> putPhoto ( $ filename , $ customPath ) ; $ resDb = $ this -> db -> postPhoto ( $ id , array ( $ key => $ customPath ) ) ; if ( $ resFs && $ resDb ) return $ filename ; return false ; }
Generate a version of the photo as specified by the width, height and options.
Generate a version of the photo as specified by the width height and options .
// TODO unlink $filename