Exemplo n.º 1
0
 /**
  * Initialize a layer from a given image path
  * 
  * From an upload form, you can give the "tmp_name" path
  * 
  * @param string $path
  * @param bool $fixOrientation
  * 
  * @return ImageWorkshopLayer
  */
 public static function initFromPath($path, $fixOrientation = false)
 {
     if (!file_exists($path)) {
         throw new ImageWorkshopException(sprintf('File "%s" not exists.', $path), static::ERROR_IMAGE_NOT_FOUND);
     }
     if (false === ($imageSizeInfos = @getImageSize($path))) {
         throw new ImageWorkshopException('Can\'t open the file at "' . $path . '" : file is not readable, did you check permissions (755 / 777) ?', static::ERROR_NOT_READABLE_FILE);
     }
     $mimeContentType = explode('/', $imageSizeInfos['mime']);
     if (!$mimeContentType || !isset($mimeContentType[1])) {
         throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "' . $path . '"', static::ERROR_NOT_AN_IMAGE_FILE);
     }
     $mimeContentType = $mimeContentType[1];
     $exif = array();
     switch ($mimeContentType) {
         case 'jpeg':
             $image = imageCreateFromJPEG($path);
             if (false === ($exif = @read_exif_data($path))) {
                 $exif = array();
             }
             break;
         case 'gif':
             $image = imageCreateFromGIF($path);
             break;
         case 'png':
             $image = imageCreateFromPNG($path);
             break;
         default:
             throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "' . $path . '"', static::ERROR_NOT_AN_IMAGE_FILE);
             break;
     }
     if (false === $image) {
         throw new ImageWorkshopException('Unable to create image with file found at "' . $path . '"');
     }
     $layer = new ImageWorkshopLayer($image, $exif);
     if ($fixOrientation) {
         $layer->fixOrientation();
     }
     return $layer;
 }
 /**
  * @param ImageWorkshopLayer $layer
  *
  * @return bool
  */
 protected function isHorizontal(ImageWorkshopLayer $layer)
 {
     return $layer->getWidth() >= $layer->getHeight();
 }
Exemplo n.º 3
0
 /**
  * Save styled image in the correct location.
  *
  * @access     public
  * @param      ImageWorkshopLayer $oLayer
  * @param      string             $sImageDir
  * @param      string             $sImageName
  * @return     string
  * @since      1.0.0-alpha
  * @version    1.0.0-alpha
  */
 public function save(ImageWorkshopLayer $oLayer, $sImageDir, $sImageName)
 {
     if (substr($sImageDir, 0, strlen(static::DIR_UPLOADS)) == static::DIR_UPLOADS) {
         $sImageDir = substr($sImageDir, strlen(static::DIR_UPLOADS));
     }
     $sSaveDir = static::DIR_IMG_STYLES . $this->sImageStyleName . '/' . $sImageDir;
     $oLayer->save($sSaveDir, $sImageName, TRUE, NULL, Config::get('base.images_quality'));
     return $sSaveDir . '/' . $sImageName;
 }