/** * Check init dimensions and getWidth and getHeight * * @test * @group rendering * @group small * @group dev * */ public function test_initImageDimensions() { $filePath = '/media/id/filePath'; $width = 640; $height = 480; // Create ImageTool Mock $imageTool = $this->getMockBuilder('\\Render\\ImageToolFactory\\ImageTool')->disableOriginalConstructor()->getMock(); $imageTool->expects($this->once())->method('getDimensionFromFile')->with($this->equalTo($filePath))->will($this->returnValue(array('width' => $width, 'height' => $height))); $imageTool->expects($this->once())->method('isImageFile')->will($this->returnValue(true)); // Create MediaContext Mock $mediaContext = $this->getMockBuilder('\\Render\\MediaContext')->disableOriginalConstructor()->getMock(); $mediaContext->expects($this->never())->method('getMediaInfoStorage')->will($this->returnValue(null)); $mediaContext->expects($this->any())->method('getImageTool')->will($this->returnValue($imageTool)); // Create MediaItem Mock $mediaItem = $this->getMockBuilder('\\Render\\APIs\\APIv1\\MediaItem')->disableOriginalConstructor()->getMock(); $mediaItem->expects($this->exactly(2))->method('getFilePath')->will($this->returnValue($filePath)); // ACT $mediaImage = new MediaImage($mediaContext, $mediaItem); // ASSERT $this->assertEquals($width, $mediaImage->getWidth()); $this->assertEquals($height, $mediaImage->getHeight()); }
/** * @param \Render\APIs\APIv1\RenderAPI $api * @param $unit * @param \Render\APIs\APIv1\MediaImage $image * @return array */ private function getImageModifications($api, $unit, $image) { $modifications = array(); $width = (int) $image->getWidth(); $height = (int) $image->getHeight(); $globalHeightPercent = str_replace('%', '', $api->getFormValue($unit, 'imgHeight')); if ($globalHeightPercent == 0) { $heightPercent = $height / $width * 100; } else { $heightPercent = $globalHeightPercent; } $cropHeight = $width * (int) $heightPercent / 100; $modifications['resize'] = array('width' => $width, 'height' => $cropHeight); // apply quality if ($api->getFormValue($unit, 'enableImageQuality')) { $modifications['quality'] = $api->getFormValue($unit, 'imageQuality'); } return $modifications; }