public function getThumbnail($path) { $gallery_path = \OCP\Config::getSystemValue('datadirectory') . '/' . \OC_User::getUser() . '/gallery'; if (file_exists($gallery_path . $path)) { return new \OC_Image($gallery_path . $path); } if (!\OC_Filesystem::file_exists($path)) { \OC_Log::write(self::TAG, 'File ' . $path . ' don\'t exists', \OC_Log::WARN); return false; } $image = new \OC_Image(); $image->loadFromFile(\OC_Filesystem::getLocalFile($path)); if (!$image->valid()) { return false; } $image->fixOrientation(); $ret = $image->preciseResize(floor(150 * $image->width() / $image->height()), 150); if (!$ret) { \OC_Log::write(self::TAG, 'Couldn\'t resize image', \OC_Log::ERROR); unset($image); return false; } $image->save($gallery_path . '/' . $path); return $image; }
/** * @param $fileId * @param $width * @param $height * * @return object|\PHPUnit_Framework_MockObject_MockObject */ private function mockGetPreview($fileId, $width, $height) { $image = new \OC_Image(file_get_contents(\OC::$SERVERROOT . '/tests/data/testimage.jpg')); $image->preciseResize($width, $height); $preview = $this->getMockBuilder('\\OC\\Preview')->disableOriginalConstructor()->getMock(); $preview->method('getPreview')->willReturn($image); $preview->method('isCached')->willReturn($fileId); return $preview; }
public function testPreciseResize() { $img = new \OC_Image(OC::$SERVERROOT . '/tests/data/testimage.png'); $this->assertTrue($img->preciseResize(128, 512)); $this->assertEquals(128, $img->width()); $this->assertEquals(512, $img->height()); $img = new \OC_Image(file_get_contents(OC::$SERVERROOT . '/tests/data/testimage.jpg')); $this->assertTrue($img->preciseResize(64, 840)); $this->assertEquals(64, $img->width()); $this->assertEquals(840, $img->height()); $img = new \OC_Image(base64_encode(file_get_contents(OC::$SERVERROOT . '/tests/data/testimage.gif'))); $this->assertTrue($img->preciseResize(1000, 1337)); $this->assertEquals(1000, $img->width()); $this->assertEquals(1337, $img->height()); }
public function getThumbnail($path) { $gallery_storage = \OCP\Files::getStorage('gallery'); if ($gallery_storage->file_exists($path)) { return new \OC_Image($gallery_storage->getLocalFile($path)); } if (!\OC_Filesystem::file_exists($path)) { \OC_Log::write(self::TAG, 'File ' . $path . ' don\'t exists', \OC_Log::WARN); return false; } $image = new \OC_Image(); $image->loadFromFile(\OC_Filesystem::getLocalFile($path)); if (!$image->valid()) { return false; } $image->fixOrientation(); $ret = $image->preciseResize(floor(self::THUMBNAIL_HEIGHT * $image->width() / $image->height()), self::THUMBNAIL_HEIGHT); if (!$ret) { \OC_Log::write(self::TAG, 'Couldn\'t resize image', \OC_Log::ERROR); unset($image); return false; } $l = $gallery_storage->getLocalFile($path); $image->save($l); return $image; }