Пример #1
0
 /**
  * Create and load an image from a string. Format is auto-detected.
  * 
  * @param string $string Binary data, i.e. from BLOB field in the database
  * @return WideImage_Image WideImage_PaletteImage or WideImage_TrueColorImage instance
  */
 static function loadFromString($string)
 {
     if (strlen($string) < 128) {
         throw new WideImage_InvalidImageSourceException("String doesn't contain image data.");
     }
     $handle = @imagecreatefromstring($string);
     if (!self::isValidImageHandle($handle)) {
         $custom_mappers = WideImage_MapperFactory::getCustomMappers();
         foreach ($custom_mappers as $mime_type => $mapper_class) {
             $mapper = WideImage_MapperFactory::selectMapper(null, $mime_type);
             $handle = $mapper->loadFromString($string);
             if (self::isValidImageHandle($handle)) {
                 break;
             }
         }
     }
     if (!self::isValidImageHandle($handle)) {
         throw new WideImage_InvalidImageSourceException("String doesn't contain valid image data.");
     }
     return self::loadFromHandle($handle);
 }