public function setup()
 {
     $this->mapper = MapperFactory::selectMapper(null, 'gif');
 }
 /**
  * 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|\WideImage\TrueColorImage
  */
 public static function loadFromString($string)
 {
     if (strlen($string) < 128) {
         throw new InvalidImageSourceException("String doesn't contain image data.");
     }
     $handle = @imagecreatefromstring($string);
     if (!static::isValidImageHandle($handle)) {
         $custom_mappers = MapperFactory::getCustomMappers();
         foreach ($custom_mappers as $mime_type => $mapper_class) {
             $mapper = MapperFactory::selectMapper(null, $mime_type);
             $handle = $mapper->loadFromString($string);
             if (static::isValidImageHandle($handle)) {
                 break;
             }
         }
     }
     if (!static::isValidImageHandle($handle)) {
         throw new InvalidImageSourceException("String doesn't contain valid image data.");
     }
     return static::loadFromHandle($handle);
 }
 /**
  * Outputs the image to browser
  * 
  * Sets headers Content-length and Content-type, and echoes the image in the specified format.
  * All other headers (such as Content-disposition) must be added manually. 
  * 
  * Example:
  * <code>
  * WideImage::load('image1.png')->resize(100, 100)->output('gif');
  * </code>
  * 
  * @param string $format Image format
  */
 public function output($format)
 {
     $args = func_get_args();
     $data = call_user_func_array(array($this, 'asString'), $args);
     $this->writeHeader('Content-length', strlen($data));
     $this->writeHeader('Content-type', MapperFactory::mimeType($format));
     echo $data;
 }
 public function testMapperBMPByURI()
 {
     $mapper = MapperFactory::selectMapper('uri.bmp');
     $this->assertInstanceOf("WideImage\\Mapper\\BMP", $mapper);
 }
Esempio n. 5
0
 /**
  * Outputs the image to browser
  *
  * Sets headers Content-length and Content-type, and echoes the image in the specified format.
  * All other headers (such as Content-disposition) must be added manually.
  *
  * Example:
  * <code>
  * WideImage::load('image1.png')->resize(100, 100)->output('gif');
  * </code>
  *
  * @param string $format Image format
  */
 public function output($format)
 {
     $args = func_get_args();
     $data = $this->asString(...$args);
     $this->writeHeader('Content-length', strlen($data));
     $this->writeHeader('Content-type', MapperFactory::mimeType($format));
     echo $data;
 }