fix overlapping pages on PDF thumbnail generation
This commit is contained in:
@@ -233,6 +233,13 @@ class MediaController extends Controller
|
||||
|
||||
if(!$exists) {
|
||||
$media->generateVariants(false);
|
||||
} else {
|
||||
// find media with the same hash that also has variants and copy them
|
||||
$mediaWithVariants = Media::where('hash', $hash)->where('variants', '!=', '')->orderBy('created_at')->first();
|
||||
if($mediaWithVariants) {
|
||||
$media->variants = $mediaWithVariants->variants;
|
||||
$media->save();
|
||||
}
|
||||
}
|
||||
|
||||
unlink($file->getRealPath());
|
||||
|
||||
@@ -158,7 +158,12 @@ class GenerateVariants implements ShouldQueue
|
||||
$height = $variantData['thumbnail']['height'];
|
||||
|
||||
$manager = new ImageManager(new Driver());
|
||||
$image = $manager->read($temp);
|
||||
|
||||
$imagick = new \Imagick();
|
||||
$imagick->readImage($temp . '[0]'); // Read the first page of the PDF
|
||||
$imagick->setImageFormat('png');
|
||||
|
||||
$image = $manager->read($imagick);
|
||||
$image->scaleDown($width, $height);
|
||||
|
||||
$variantFile = $tempDir . '/' . $media->hash . '-thumbnail.webp';
|
||||
|
||||
Reference in New Issue
Block a user