Пример #1
0
 /**
  * @covers MemePuush\Image::output
  * @covers MemePuush\Image::getOutputFilename
  */
 public function testOutputFilename()
 {
     $imagick = $this->getMock('Imagick', array('getImageGeometry', 'getImageSignature', 'setImageFormat', 'setCompression', 'setCompressionQuality', 'writeImage', 'queryFontMetrics', 'annotateImage'), array());
     $imagick->expects($this->any())->method('getImageGeometry')->will($this->returnValue(array('width' => 283, 'height' => 445)));
     $this->object->setImage($imagick);
     $draw = $this->getMock('ImagickDraw', array('setFont', 'setFontSize', 'setFontWeight', 'setStrokeColor', 'setStrokeWidth', 'setStrokeAntialias', 'setStrokeAlpha', 'setFillAlpha', 'setTextAntialias', 'setTextAlignment', 'setTextKerning', 'setGravity', 'setFillColor', 'rectangle'), array());
     $this->object->setTopCaption('something');
     $this->object->getTopCaption()->setDraw($draw);
     $this->object->getTopCaption()->setGravity(2);
     $this->object->setBottomCaption('');
     $this->object->getBottomCaption()->setDraw($draw);
     $this->object->getBottomCaption()->setGravity(2);
     $this->assertEquals('0da702af.jpg', $this->object->getOutputFilename());
 }
Пример #2
0
     $img = isset($_GET['img']) ? $_GET['img'] : '';
     if ($output == 'puush' && !$apiKey) {
         throw new \Exception('Puu.sh api key must be provided');
     }
     if (!$t1 && !$t2) {
         throw new \Exception('No caption provided');
     }
     if (!$img) {
         throw new \Exception('No image url provided');
     }
     $image = new Image($img);
     //if the image doesn't exist, cannot continue
     //if( !$image )
     //    throw new \Exception( 'Could not load image: ' . $img );
     $image->setOutputFormat($output, $apiKey);
     $image->setTopCaption($t1);
     $image->setBottomCaption($t2);
     $outputContent = $image->output();
     switch ($output) {
         case 'screen':
             header('Content-type: image/jpg');
             echo file_get_contents($outputContent);
             break;
         case 'file':
             echo $outputContent;
             break;
         case 'puush':
             echo json_encode(array('url' => $outputContent));
             break;
     }
 } catch (\Exception $e) {