Пример #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);
 }
Пример #2
0
 public function setup()
 {
     $this->mapper = WideImage_MapperFactory::selectMapper(null, 'gd');
 }
Пример #3
0
 /**
  * Returns binary string with image data in format specified by $format
  * 
  * Additional parameters may be passed to the function. See WideImage_Image::saveToFile() for more details.
  * 
  * @param string $format The format of the image
  * @return string The binary image data in specified format
  */
 function asString($format)
 {
     ob_start();
     $args = func_get_args();
     $args[0] = null;
     array_unshift($args, $this->getHandle());
     $mapper = WideImage_MapperFactory::selectMapper(null, $format);
     $res = call_user_func_array(array($mapper, 'save'), $args);
     if (!$res) {
         throw new WideImage_UnknownErrorWhileMappingException(get_class($mapper) . " returned an invalid result while writing the image data");
     }
     return ob_get_clean();
 }
Пример #4
0
 /**
  * Create and load an image from a file or URL. You can override the file 
  * format by specifying the second parameter.
  * 
  * @param string $uri File or url
  * @param string $format *DEPRECATED* Format hint, usually not needed
  * @return WideImage_Image WideImage_PaletteImage or WideImage_TrueColorImage instance
  */
 static function loadFromFile($uri, $format = null)
 {
     $data = file_get_contents($uri);
     $handle = @imagecreatefromstring($data);
     if (!self::isValidImageHandle($handle)) {
         $mapper = WideImage_MapperFactory::selectMapper($uri, $format);
         $handle = $mapper->load($uri);
     }
     if (!self::isValidImageHandle($handle)) {
         throw new WideImage_InvalidImageSourceException("File '{$uri}' appears to be an invalid image source.");
     }
     return self::loadFromHandle($handle);
 }
Пример #5
0
 public function testMapperBMPByURI()
 {
     $mapper = WideImage_MapperFactory::selectMapper('uri.bmp');
     $this->assertInstanceOf('WideImage_Mapper_BMP', $mapper);
 }
Пример #6
0
 /**
  * Returns binary string with image data in format specified by $format
  * 
  * Additional parameters may be passed to the function. See WideImage_Image::saveToFile() for more details.
  * 
  * @param string $format The format of the image
  * @return string The binary image data in specified format
  */
 function asString($format)
 {
     ob_start();
     $args = func_get_args();
     $args[0] = null;
     array_unshift($args, $this->getHandle());
     $mapper = WideImage_MapperFactory::selectMapper(null, $format);
     call_user_func_array(array($mapper, 'save'), $args);
     return ob_get_clean();
 }