/**
  * Returns a mapper, based on the $uri and $format
  * 
  * @param string $uri File URI
  * @param string $format File format (extension or mime-type) or null
  * @return WideImage_Mapper
  **/
 static function selectMapper($uri, $format = null)
 {
     $format = self::determineFormat($uri, $format);
     if (array_key_exists($format, self::$mappers)) {
         return self::$mappers[$format];
     }
     $mapperClassName = 'WideImage_Mapper_' . $format;
     if (!class_exists($mapperClassName, false)) {
         $mapperFileName = WideImage::path() . 'Mapper/' . $format . '.php';
         if (file_exists($mapperFileName)) {
             require_once $mapperFileName;
         }
     }
     if (class_exists($mapperClassName)) {
         self::$mappers[$format] = new $mapperClassName();
         return self::$mappers[$format];
     }
     throw new WideImage_UnsupportedFormatException("Format '{$format}' is not supported.");
 }
Example #2
0
 public static function create($config = [])
 {
     if (!empty($config)) {
         if (!empty($config['tmpName'])) {
             $dirName = $config['dirName'];
             $rensize = WideImage::load($config['tmpName']);
             self::dir($dirName);
             chmod($dirName, 0777);
             $big = WWW_ROOT . '/images/' . $dirName . '/big/' . $config['name'];
             $small = WWW_ROOT . '/images/' . $dirName . '/small/' . $config['name'];
             $im = imagecreatefromstring($rensize->resize(370, 281));
             imagejpeg($im, $small);
             $imb = imagecreatefromstring($rensize->resize(767, 511));
             imagejpeg($imb, $big);
             chmod($small, 0777);
             chmod($big, 0777);
         }
     } else {
         return '';
     }
 }
 public function actionUpload()
 {
     $model = $this->findModel();
     $file = UploadFile::load($model, 'file');
     if (empty($file)) {
         throw new Exception("Error Processing Request", 401);
     }
     $widimage = WideImage::load($file->tmpName);
     $name = $model->nome . '-' . $model->id . '.' . $file->typeName;
     $resize = $widimage->resize(255, 255);
     //verificando se existe foto
     $fileName = static::dir() . $model->file;
     if (file_exists($fileName)) {
         unlink($fileName);
     }
     $filename = static::dir() . $name;
     $resize->saveToFile($filename);
     $model->file = $name;
     $model->save();
     chmod($filename, 0777);
     Session::setSession(['photo' => $model->file]);
     $this->Json(['files' => [['url' => $this->createUrl() . '/app/assets/arquivos/profile/' . $model->file]]]);
 }
 /**
  * (non-PHPdoc)
  * @see WideImage_Image#asTrueColor()
  */
 function asTrueColor()
 {
     $width = $this->getWidth();
     $height = $this->getHeight();
     $new = WideImage::createTrueColorImage($width, $height);
     if ($this->isTransparent()) {
         $new->copyTransparencyFrom($this);
     }
     if (!imageCopy($new->getHandle(), $this->handle, 0, 0, 0, 0, $width, $height)) {
         throw new WideImage_GDFunctionResultException("imagecopy() returned false");
     }
     return $new;
 }
Example #5
0
     */
    static function createTrueColorImage($width, $height)
    {
        return WideImage_TrueColorImage::create($width, $height);
    }
    /**
     * Check whether the given handle is a valid GD resource
     * 
     * @param mixed $handle The variable to check
     * @return bool
     */
    static function isValidImageHandle($handle)
    {
        return is_resource($handle) && get_resource_type($handle) == 'gd';
    }
    /**
     * Throws exception if the handle isn't a valid GD resource
     * 
     * @param mixed $handle The variable to check
     */
    static function assertValidImageHandle($handle)
    {
        if (!self::isValidImageHandle($handle)) {
            throw new WideImage_InvalidImageHandleException("{$handle} is not a valid image handle.");
        }
    }
}
WideImage::checkGD();
WideImage::registerCustomMapper('WideImage_Mapper_BMP', 'image/bmp', 'bmp');
WideImage::registerCustomMapper('WideImage_Mapper_TGA', 'image/tga', 'tga');
 /**
  * Restores an image from serialization. Called automatically upon unserialize().
  */
 function __wakeup()
 {
     $temp_image = WideImage::loadFromString($this->sdata);
     $temp_image->releaseHandle();
     $this->handle = $temp_image->handle;
     $temp_image = null;
     $this->sdata = null;
 }