/** * Generate thumbnail of an Image with GD * @param string $viewPath Source view path * @param string $srcImagePath Source image path relative to the ownCloud fakeroot * @param string $dstImagePath Destination image path * @return boolean TRUE image generated successfully, FALSE otherwise */ private function generateImageThumbnailGD($viewPath, $srcImagePath, $dstImagePath) { $view = new \OC\Files\View($viewPath); $imageLocalPath = $view->getLocalFile($srcImagePath); $image = new \OCP\Image(); $image->loadFromFile($imageLocalPath); if (!$image->valid()) { return FALSE; } //Non legge il path $image->fixOrientation(); $image->resize($this->width); $imageRsrc = $image->resource(); $height = $image->height(); $width = $image->width(); $widthOffset = intval(($this->width - $width) / 2); $heightOffset = intval(($this->height - $height) / 2); $thumbGDImage = imagecreatetruecolor($this->width, $this->height); // Fill with background color $bgColor = imagecolorallocate($thumbGDImage, $this->bgColor['red'], $this->bgColor['green'], $this->bgColor['blue']); imagefilledrectangle($thumbGDImage, 0, 0, $this->width, $this->height, $bgColor); imagecopyresampled($thumbGDImage, $imageRsrc, $widthOffset, $heightOffset, 0, 0, $width, $height, $width, $height); imagepng($thumbGDImage, $dstImagePath, 7); imagedestroy($thumbGDImage); return TRUE; }