Created
May 10, 2023 00:58
-
-
Save aldhinya/5afc987375e76703e9d7a1ef1e74a524 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use Imagick; | |
$pdf = PDF::loadView('mitra.plotkunjungan.pdf', compact('surat'))->setPaper('a4', 'potrait');; | |
$path = public_path('docs/'); | |
$fileName = time() . '.' . 'pdf'; | |
$path_pdf = $path . $fileName; | |
$pdf->save($path_pdf); | |
$path_img = str_replace('pdf', 'jpg', $path_pdf); | |
$imgExt = new Imagick(); | |
$imgExt->setResolution(200, 200); | |
$imgExt->readImage($path_pdf . "[0]"); | |
$imgExt->setImageFormat('png'); | |
$imgExt->setImageBackgroundColor('#ffffff'); | |
$imgExt->setImageAlphaChannel(Imagick::ALPHACHANNEL_REMOVE); | |
$imgExt = $imgExt->mergeImageLayers(Imagick::LAYERMETHOD_FLATTEN); | |
$imgExt->setImageCompression(Imagick::COMPRESSION_JPEG); | |
$imgExt->setImageCompressionQuality(10); | |
$imgExt->resizeImage(2480, 3508, Imagick::FILTER_CUBIC, 1); | |
$imgExt->writeImages($path_img, true); | |
$imgExt->clear(); | |
$imgExt->destroy(); | |
File::delete($path_pdf); | |
$bg = base64_encode(file_get_contents($path_img)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment