public function testDecodeEncoded()
 {
     // create two resource
     $res1 = imagecreatetruecolor(20, 15);
     imagefill($res1, 0, 0, 850736919);
     $res2 = imagecreatetruecolor(20, 15);
     imagefill($res1, 0, 0, 11876119);
     // create encoded
     $encoder = new Encoder();
     $encoder->setCanvas(20, 15);
     $encoder->setLoops(2);
     $encoder->createFrameFromGdResource($res1, 100);
     $encoder->createFrameFromGdResource($res2, 100);
     $encoded = $encoder->encode();
     // decode encoded
     $decoder = new Decoder();
     $decoder->initFromData($encoded);
     $decoded = $decoder->decode();
     // check after decoding
     $this->assertEquals(20, $decoded->getCanvasWidth());
     $this->assertEquals(15, $decoded->getCanvasHeight());
     $this->assertEquals(2, $decoded->countFrames());
     $this->assertEquals(2, $decoded->getLoops());
     $this->assertEquals(32, $decoded->countGlobalColors());
     $this->assertFalse($decoded->hasGlobalColorTable());
     foreach ($decoded->getFrames() as $frame) {
         $this->assertEquals(100, $frame->getDelay());
     }
 }
 public function testSetCanvas()
 {
     $encoder = new Encoder();
     $result = $encoder->setCanvas(300, 200);
     $this->assertInstanceOf('Intervention\\Gif\\Encoder', $result);
     $this->assertEquals(300, $encoder->canvasWidth);
     $this->assertEquals(200, $encoder->canvasHeight);
 }
Exemplo n.º 3
0
 /**
  * Processes and returns encoded image as GIF string
  *
  * @return string
  */
 protected function processGif()
 {
     $image = $this->image;
     $encoder = new GifEncoder();
     $encoder->setCanvas($image->getWidth(), $image->getHeight());
     $encoder->setLoops($image->getContainer()->getLoops());
     // set frames
     foreach ($image as $frame) {
         // extract each frame
         ob_start();
         imagegif($frame->getCore());
         $frame_data = ob_get_contents();
         ob_end_clean();
         // decode frame
         $decoder = new GifDecoder();
         $decoder->initFromData($frame_data);
         $decoded = $decoder->decode();
         // add each frame
         $encoder->addFrame($decoded->getFrame()->setLocalColorTable($decoded->getGlobalColorTable())->setDelay($frame->delay));
     }
     return $encoder->encode();
 }