/** * Retrieves the preview from the cache and resizes it if necessary * * @param int $fileId fileId of the original image * @param string $cached the path to the cached preview */ private function getCachedPreview($fileId, $cached) { $stream = $this->userView->fopen($cached, 'r'); $this->preview = null; if ($stream) { $image = new \OC_Image(); $image->loadFromFileHandle($stream); $this->preview = $image->valid() ? $image : null; if (!is_null($this->preview)) { // Size of the preview we calculated $maxX = $this->previewWidth; $maxY = $this->previewHeight; // Size of the preview we retrieved from the cache $previewX = (int)$this->preview->width(); $previewY = (int)$this->preview->height(); // We don't have an exact match if ($previewX !== $maxX || $previewY !== $maxY) { $this->resizeAndStore($fileId); } } fclose($stream); } }
/** * Retrieves the preview from the cache and resizes it if necessary * * @param int $fileId fileId of the original image * @param string $cached the path to the cached preview */ private function getCachedPreview($fileId, $cached) { $stream = $this->userView->fopen($cached, 'r'); $this->preview = null; if ($stream) { $image = new \OC_Image(); $image->loadFromFileHandle($stream); $this->preview = $image->valid() ? $image : null; $maxX = (int) $this->getMaxX(); $maxY = (int) $this->getMaxY(); $previewX = (int) $this->preview->width(); $previewY = (int) $this->preview->height(); if ($previewX !== $maxX && $previewY !== $maxY) { $this->resizeAndStore($fileId); } fclose($stream); } }
/** * Tests if a max size preview of smaller dimensions can be created * * @param \OCP\IImage $preview */ private function doesPreviewFit($preview) { $maxDimRatio = round($this->maxWidth / $this->maxHeight, 2); $previewRatio = round($preview->width() / $preview->height(), 2); // Testing code /*print_r("mw $this->maxWidth "); print_r("mh $this->maxHeight "); print_r("mr $maxDimRatio "); $pw = $preview->width(); $ph = $preview->height(); print_r("pw $pw "); print_r("ph $ph "); print_r("pr $previewRatio ");*/ if ($maxDimRatio < $previewRatio) { $this->assertLessThanOrEqual($this->maxWidth, $preview->width()); $this->assertLessThan($this->maxHeight, $preview->height()); } elseif ($maxDimRatio > $previewRatio) { $this->assertLessThan($this->maxWidth, $preview->width()); $this->assertLessThanOrEqual($this->maxHeight, $preview->height()); } else { // Original had to be resized $this->assertLessThanOrEqual($this->maxWidth, $preview->width()); $this->assertLessThanOrEqual($this->maxHeight, $preview->height()); } }