protected function _createImgPreview($inputFile = null) {
		$result = [];
		if (empty($inputFile) || !file_exists($inputFile)) {
			return $result;
		}

		$previewFullPath = $this->_getPreviewDir();
		$wwwRoot = Configure::read('App.www_root');
		if (empty($wwwRoot)) {
			throw new InternalErrorException(__d('view_extension', 'Invalid path to "www_root" directory'));
		}

		$wwwRootPos = mb_stripos($previewFullPath, $wwwRoot);
		if ($wwwRootPos !== 0) {
			throw new InternalErrorException(__d('view_extension', 'Path to preview directory is not contain path to "www_root" directory'));
		}

		$previewWebRootPath = mb_substr($previewFullPath, mb_strlen($wwwRoot) - 1);
		if (empty($previewWebRootPath)) {
			throw new InternalErrorException(__d('view_extension', 'Invalid path to preview directory'));
		}

		$jpgTempFile = uniqid();
		$im = new Imagick();
		$im->setResolution(150, 150);
		if (!$im->readimage($inputFile)) {
			$im->clear();
			$im->destroy();

			return $result;
		}

		$numPages = $im->getNumberImages();
		for ($page = 0; $page < $numPages; $page++) {
			$postfix = '[' . $page . ']';
			$previewFile = $jpgTempFile . $postfix . '.jpg';
			if (!$im->readimage($inputFile . $postfix)) {
				continue;
			}

			$im->setImageFormat('jpeg');
			$im->setImageCompressionQuality(90);
			if ($im->writeImage($previewFullPath . $previewFile)) {
				$result[] = $previewWebRootPath . $previewFile;
			}
		}

		$im->clear();
		$im->destroy();
		if (!empty($result) && (DIRECTORY_SEPARATOR === '\\')) {
			foreach ($result as &$resultItem) {
				$resultItem = mb_ereg_replace('\\\\', '/', $resultItem);
			}
		}

		return $result;
	}
protected function _createImgPreview($inputFile = null) {
		$result = [];
		if (empty($inputFile) || !file_exists($inputFile)) {
			return $result;
		}

		$previewFullPath = $this->_getPreviewDir();
		$wwwRoot = Configure::read('App.www_root');
		if (empty($wwwRoot)) {
			throw new InternalErrorException(__d('view_extension', 'Invalid path to "www_root" directory'));
		}

		$wwwRootPos = mb_stripos($previewFullPath, $wwwRoot);
		if ($wwwRootPos !== 0) {
			throw new InternalErrorException(__d('view_extension', 'Path to preview directory is not contain path to "www_root" directory'));
		}

		$previewWebRootPath = mb_substr($previewFullPath, mb_strlen($wwwRoot) - 1);
		if (empty($previewWebRootPath)) {
			throw new InternalErrorException(__d('view_extension', 'Invalid path to preview directory'));
		}

		$jpgTempFile = uniqid();
		$im = new Imagick();
		$im->setResolution(150, 150);
		if (!$im->readimage($inputFile)) {
			$im->clear();
			$im->destroy();

			return $result;
		}

		$numPages = $im->getNumberImages();
		for ($page = 0; $page < $numPages; $page++) {
			$postfix = '[' . $page . ']';
			$previewFile = $jpgTempFile . $postfix . '.jpg';
			if (!$im->readimage($inputFile . $postfix)) {
				continue;
			}

			$im->setImageFormat('jpeg');
			$im->setImageCompressionQuality(90);
			if ($im->writeImage($previewFullPath . $previewFile)) {
				$result[] = $previewWebRootPath . $previewFile;
			}
		}

		$im->clear();
		$im->destroy();
		if (!empty($result) && (DIRECTORY_SEPARATOR === '\\')) {
			foreach ($result as &$resultItem) {
				$resultItem = mb_ereg_replace('\\\\', '/', $resultItem);
			}
		}

		return $result;
	}
protected function _createImgPreview ( $ inputFile = null ) { $ result = [ ] ; if ( empty ( $ inputFile ) || ! file_exists ( $ inputFile ) ) { return $ result ; } $ previewFullPath = $ this -> _getPreviewDir ( ) ; $ wwwRoot = Configure :: read ( 'App.www_root' ) ; if ( empty ( $ wwwRoot ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Invalid path to "www_root" directory' ) ) ; } $ wwwRootPos = mb_stripos ( $ previewFullPath , $ wwwRoot ) ; if ( $ wwwRootPos !== 0 ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Path to preview directory is not contain path to "www_root" directory' ) ) ; } $ previewWebRootPath = mb_substr ( $ previewFullPath , mb_strlen ( $ wwwRoot ) - 1 ) ; if ( empty ( $ previewWebRootPath ) ) { throw new InternalErrorException ( __d ( 'view_extension' , 'Invalid path to preview directory' ) ) ; } $ jpgTempFile = uniqid ( ) ; $ im = new Imagick ( ) ; $ im -> setResolution ( 150 , 150 ) ; if ( ! $ im -> readimage ( $ inputFile ) ) { $ im -> clear ( ) ; $ im -> destroy ( ) ; return $ result ; } $ numPages = $ im -> getNumberImages ( ) ; for ( $ page = 0 ; $ page < $ numPages ; $ page ++ ) { $ postfix = '[' . $ page . ']' ; $ previewFile = $ jpgTempFile . $ postfix . '.jpg' ; if ( ! $ im -> readimage ( $ inputFile . $ postfix ) ) { continue ; } $ im -> setImageFormat ( 'jpeg' ) ; $ im -> setImageCompressionQuality ( 90 ) ; if ( $ im -> writeImage ( $ previewFullPath . $ previewFile ) ) { $ result [ ] = $ previewWebRootPath . $ previewFile ; } } $ im -> clear ( ) ; $ im -> destroy ( ) ; if ( ! empty ( $ result ) && ( DIRECTORY_SEPARATOR === '\\' ) ) { foreach ( $ result as & $ resultItem ) { $ resultItem = mb_ereg_replace ( '\\\\' , '/' , $ resultItem ) ; } } return $ result ; }
Creating images of every page for preview file

@param string $inputFile Input file for creating images.
@throws InternalErrorException if empty path to www_root folder.
@throws InternalErrorException if Path to preview folder is not
contain path to www_root folder.
@throws InternalErrorException if empty path to preview folder.
@return array Return array of relative path to preview images of pages.
Creating images of every page for preview file