public function testKeepAspectRatioCover() { $originalWidth = 1680; $originalHeight = 1050; $originalAspectRation = $originalWidth / $originalHeight; $preview = new \OC\Preview(self::TEST_PREVIEW_USER1, 'files/', 'testimage.jpg', 150, 150); $preview->setKeepAspect(true); $preview->setMode(\OC\Preview::MODE_COVER); $image = $preview->getPreview(); $aspectRatio = $image->width() / $image->height(); $this->assertEquals(round($originalAspectRation, 2), round($aspectRatio, 2)); $this->assertGreaterThanOrEqual(150, $image->width()); $this->assertGreaterThanOrEqual(150, $image->height()); }
$maxX = array_key_exists('x', $_GET) ? (int) $_GET['x'] : '32'; $maxY = array_key_exists('y', $_GET) ? (int) $_GET['y'] : '32'; $scalingUp = array_key_exists('scalingup', $_GET) ? (bool) $_GET['scalingup'] : true; $keepAspect = array_key_exists('a', $_GET) ? true : false; $always = array_key_exists('forceIcon', $_GET) ? (bool) $_GET['forceIcon'] : true; $mode = array_key_exists('mode', $_GET) ? $_GET['mode'] : 'fill'; if ($file === '') { //400 Bad Request \OC_Response::setStatus(400); \OCP\Util::writeLog('core-preview', 'No file parameter was passed', \OCP\Util::DEBUG); exit; } if ($maxX === 0 || $maxY === 0) { //400 Bad Request \OC_Response::setStatus(400); \OCP\Util::writeLog('core-preview', 'x and/or y set to 0', \OCP\Util::DEBUG); exit; } $info = \OC\Files\Filesystem::getFileInfo($file); if (!$info instanceof OCP\Files\FileInfo || !$always && !\OC::$server->getPreviewManager()->isAvailable($info)) { \OC_Response::setStatus(404); } else { $preview = new \OC\Preview(\OC_User::getUser(), 'files'); $preview->setFile($file, $info); $preview->setMaxX($maxX); $preview->setMaxY($maxY); $preview->setScalingUp($scalingUp); $preview->setMode($mode); $preview->setKeepAspect($keepAspect); $preview->showPreview(); }