/** * @return \Imagick */ public function output() { switch (strtolower($this->outputFormat)) { case 'puush': $this->output = new Puush($this->getApiKey()); break; default: //generate file $this->output = new File(); break; } //get imagick image $image = $this->getImage(); $this->output->addHashInput($image->getImageSignature()); $this->output->addHashInput($this->getTopCaption()->getText()); $this->output->addHashInput($this->getBottomCaption()->getText()); if (!$this->output->exists()) { if (!$this->topCaption->isEmpty()) { $this->topCaption->annotateImage(); } if (!$this->bottomCaption->isEmpty()) { $this->bottomCaption->annotateImage(); } $image->setImageFormat("jpg"); //$image->setCompression( Imagick::COMPRESSION_JPEG ); $image->setCompressionQuality(70); $this->output->upload($image); } return $this->output->getOutputPath(); }
/** * @covers MemePuush\Caption::annotateImage */ public function testAnnotateImageDebug() { $image = new Image(); $imagick = $this->getMock('Imagick', array('getImageGeometry', 'queryFontMetrics', 'annotateImage', 'drawImage'), array()); $imagick->expects($this->any())->method('getImageGeometry')->will($this->returnValue(array('width' => 283, 'height' => 445))); $properties = array('{"characterWidth":1,"characterHeight":1,"ascender":2,"descender":-1,"textWidth":68,"textHeight":1,"maxHorizontalAdvance":1,"boundingBox":{"x1":0,"y1":-0.015625,"x2":0.8125,"y2":0.8125},"originX":68.265625,"originY":0}', '{"characterWidth":4,"characterHeight":4,"ascender":5,"descender":-1,"textWidth":141.03125,"textHeight":5,"maxHorizontalAdvance":5,"boundingBox":{"x1":-0.03125,"y1":-0.0625,"x2":3.265625,"y2":3.234375},"originX":140.265625,"originY":0}', '{"characterWidth":6,"characterHeight":6,"ascender":7,"descender":-2,"textWidth":191.03125,"textHeight":7,"maxHorizontalAdvance":8,"boundingBox":{"x1":-0.03125,"y1":-0.09375,"x2":4.890625,"y2":4.84375},"originX":190.265625,"originY":0}', '{"characterWidth":8,"characterHeight":8,"ascender":9,"descender":-2,"textWidth":238.046875,"textHeight":10,"maxHorizontalAdvance":10,"boundingBox":{"x1":-0.046875,"y1":-0.140625,"x2":6.515625,"y2":6.453125},"originX":237.265625,"originY":0}', '{"characterWidth":9,"characterHeight":9,"ascender":10,"descender":-2,"textWidth":287,"textHeight":11,"maxHorizontalAdvance":12,"boundingBox":{"x1":0,"y1":0,"x2":6,"y2":7},"originX":287.265625,"originY":0}', '{"characterWidth":10,"characterHeight":10,"ascender":11,"descender":-3,"textWidth":301,"textHeight":12,"maxHorizontalAdvance":13,"boundingBox":{"x1":0,"y1":0,"x2":7,"y2":8},"originX":301.265625,"originY":0}', '{"characterWidth":11,"characterHeight":11,"ascender":12,"descender":-3,"textWidth":147,"textHeight":45,"maxHorizontalAdvance":14,"boundingBox":{"x1":-1,"y1":0,"x2":8,"y2":9},"originX":146.765625,"originY":0}', '{"characterWidth":13,"characterHeight":13,"ascender":14,"descender":-3,"textWidth":170,"textHeight":51,"maxHorizontalAdvance":17,"boundingBox":{"x1":0,"y1":0,"x2":10,"y2":10},"originX":170.765625,"originY":0}', '{"characterWidth":15,"characterHeight":15,"ascender":16,"descender":-4,"textWidth":192.5,"textHeight":60,"maxHorizontalAdvance":19,"boundingBox":{"x1":-0.5,"y1":0,"x2":11,"y2":12},"originX":192.765625,"originY":0}', '{"characterWidth":17,"characterHeight":17,"ascender":18,"descender":-4,"textWidth":216,"textHeight":66,"maxHorizontalAdvance":22,"boundingBox":{"x1":0,"y1":0,"x2":13,"y2":13},"originX":216.765625,"originY":0}', '{"characterWidth":18,"characterHeight":18,"ascender":19,"descender":-4,"textWidth":228,"textHeight":69,"maxHorizontalAdvance":23,"boundingBox":{"x1":0,"y1":0,"x2":14,"y2":14},"originX":228.765625,"originY":0}', '{"characterWidth":19,"characterHeight":19,"ascender":20,"descender":-5,"textWidth":239.5,"textHeight":75,"maxHorizontalAdvance":24,"boundingBox":{"x1":-0.5,"y1":0,"x2":14,"y2":15},"originX":239.765625,"originY":0}', '{"characterWidth":20,"characterHeight":20,"ascender":21,"descender":-5,"textWidth":256.5,"textHeight":78,"maxHorizontalAdvance":26,"boundingBox":{"x1":-0.5,"y1":0,"x2":15,"y2":16},"originX":256.765625,"originY":0}', '{"characterWidth":21,"characterHeight":21,"ascender":22,"descender":-5,"textWidth":267,"textHeight":81,"maxHorizontalAdvance":27,"boundingBox":{"x1":0,"y1":0,"x2":15,"y2":17},"originX":267.765625,"originY":0}', '{"characterWidth":22,"characterHeight":22,"ascender":23,"descender":-5,"textWidth":274.5,"textHeight":84,"maxHorizontalAdvance":28,"boundingBox":{"x1":-0.5,"y1":0,"x2":17,"y2":17},"originX":274.765625,"originY":0}', '{"characterWidth":23,"characterHeight":23,"ascender":24,"descender":-5,"textWidth":294.5,"textHeight":87,"maxHorizontalAdvance":30,"boundingBox":{"x1":-0.5,"y1":0,"x2":17,"y2":18},"originX":294.765625,"originY":0}'); foreach ($properties as $i => $returnVal) { $imagick->expects($this->at($i + 1))->method('queryFontMetrics')->will($this->returnValue(json_decode($returnVal, true))); } $image->setImage($imagick); $object = new Caption($image, 'it\'s a long description with lots of words and word wrapping'); $object->setDebug(true); $draw = $this->getMock('ImagickDraw', array('setFont', 'setFontSize', 'setFontWeight', 'setStrokeColor', 'setStrokeWidth', 'setStrokeAntialias', 'setStrokeAlpha', 'setFillAlpha', 'setTextAntialias', 'setTextAlignment', 'setTextKerning', 'setGravity', 'setFillColor', 'rectangle'), array()); $object->setDraw($draw); $pixel = $this->getMock('ImagickPixel'); $object->setPixel($pixel); $object->setGravity(2); $object->annotateImage(); $this->assertEquals(21, $object->getFontSize()); }