Example #1
0
 /**
  * {@inheritdoc}
  */
 public function apply(Video $video, VideoInterface $format)
 {
     foreach ($video->getStreams()->videos() as $stream) {
         if ($stream->has('width') && $stream->has('height')) {
             $stream->set('width', $this->dimension->getWidth());
             $stream->set('height', $this->dimension->getHeight());
         }
     }
     return array('-filter:v', 'crop=' . $this->dimension->getWidth() . ':' . $this->dimension->getHeight() . ':' . $this->point->getX() . ':' . $this->point->getY());
 }
Example #2
0
 public function testCommandParamsAreCorrectAndStreamIsUpdated()
 {
     $stream = new Stream(array('width' => 320, 'height' => 240, 'codec_type' => 'video'));
     $streams = new StreamCollection(array($stream));
     $video = $this->getVideoMock();
     $video->expects($this->once())->method('getStreams')->will($this->returnValue($streams));
     $format = $this->getMock('FFMpeg\\Format\\VideoInterface');
     $dimension = new Dimension(200, 150);
     $point = new Point(25, 35);
     $filter = new CropFilter($point, $dimension);
     $expected = array('-filter:v', 'crop=' . $dimension->getWidth() . ":" . $dimension->getHeight() . ":" . $point->getX() . ":" . $point->getY());
     $this->assertEquals($expected, $filter->apply($video, $format));
     $this->assertEquals(200, $stream->get('width'));
     $this->assertEquals(150, $stream->get('height'));
 }
Example #3
0
 private function getComputedDimensions(Dimension $dimension, $modulus)
 {
     $originalRatio = $dimension->getRatio($this->forceStandards);
     switch ($this->mode) {
         case self::RESIZEMODE_SCALE_WIDTH:
             $height = $this->dimension->getHeight();
             $width = $originalRatio->calculateWidth($height, $modulus);
             break;
         case self::RESIZEMODE_SCALE_HEIGHT:
             $width = $this->dimension->getWidth();
             $height = $originalRatio->calculateHeight($width, $modulus);
             break;
         case self::RESIZEMODE_INSET:
             $targetRatio = $this->dimension->getRatio($this->forceStandards);
             if ($targetRatio->getValue() > $originalRatio->getValue()) {
                 $height = $this->dimension->getHeight();
                 $width = $originalRatio->calculateWidth($height, $modulus);
             } else {
                 $width = $this->dimension->getWidth();
                 $height = $originalRatio->calculateHeight($width, $modulus);
             }
             break;
         case self::RESIZEMODE_FIT:
         default:
             $width = $this->dimension->getWidth();
             $height = $this->dimension->getHeight();
             break;
     }
     return new Dimension($width, $height);
 }
Example #4
0
 public function testGetters()
 {
     $dimension = new Dimension(320, 240);
     $this->assertEquals(320, $dimension->getWidth());
     $this->assertEquals(240, $dimension->getHeight());
 }
Example #5
0
 /**
  * Creates a ratio based on Dimension.
  *
  * The strategy parameter forces by default to use standardized ratios. If
  * custom ratio need to be used, disable it.
  *
  * @param Dimension $dimension
  * @param Boolean   $forceStandards Whether to force or not standard ratios
  *
  * @return AspectRatio
  *
  * @throws InvalidArgumentException
  */
 public static function create(Dimension $dimension, $forceStandards = true)
 {
     $incoming = $dimension->getWidth() / $dimension->getHeight();
     if ($forceStandards) {
         return new static(static::nearestStrategy($incoming));
     } else {
         return new static(static::customStrategy($incoming));
     }
 }