public function MediaPdfThumbnailImagickManager::generateImage in Media PDF Thumbnail 8
Same name and namespace in other branches
- 8.2 src/Manager/MediaPdfThumbnailImagickManager.php \Drupal\media_pdf_thumbnail\Manager\MediaPdfThumbnailImagickManager::generateImage()
Generate image from PDF file.
Parameters
string $source: File source.
string $target: File target.
Return value
string File path.
Throws
\ImagickException
File
- src/
Manager/ MediaPdfThumbnailImagickManager.php, line 27
Class
- MediaPdfThumbnailImagickManager
- Class MediaPdfThumbnailImagickManager.
Namespace
Drupal\media_pdf_thumbnail\ManagerCode
public function generateImage($source, $target) {
$target = dirname($source) . DIRECTORY_SEPARATOR . $target;
$im = new Imagick($source . "[0]");
$im
->setimageformat("png");
$im
->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE);
$im
->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN);
$im
->setImageBackgroundColor('white');
$im
->thumbnailimage(2480, 3508);
$im
->writeimage($target);
$fileName = $im
->getImageFilename();
$im
->clear();
$im
->destroy();
return $this
->moveImageToThumbnailFolder($fileName);
}