Hi - I am trying to create a thumbnail from a pdf which is uploaded via the file uploaded - all on the backend. I was able to create the thumbnail using Imagick, but only if the pdf has already been uploaded. I did this using the beforeSave function:
if (!empty($this->invoice->disk_name))
{
$pdfDiskName = $this->invoice->disk_name;
$pdfImage = substr_replace($pdfDiskName, 'jpg', strrpos($pdfDiskName, ".") +1);
$pdfPathFile = $this->invoice->getPath();
$image = new Imagick();
$image->setResolution(300,300);
$image->readImage($pdfPathFile);
$image->setCompressionQuality(100);
$image->setImageFormat('jpg');
$image->writeImage($pdfImage);
$this->invoice_image = $pdfImage;
}
Without the condition, you get an error because the $this->invoice_disk_name is null until the record is saved. Any suggestions as how to accomplish this when you are creating the record or when updating a record without a loaded pdf file are appreciated. I looked into deferred bindings but I was unable to get it to work.
Thanks.