Update (seo)

Add (lqip)
This commit is contained in:
2023-09-25 02:41:40 +08:00
parent ef9c5a1407
commit 3aa6367e83
20 changed files with 163 additions and 38 deletions

View File

@@ -208,7 +208,9 @@ public static function handle($post)
$yPosition += $fontSize + $padding;
}
$filename = $post->slug.'-'.epoch_now_timestamp().'.jpg';
$epoch_now_timestamp = epoch_now_timestamp();
$filename = $post->slug.'-'.$epoch_now_timestamp.'.jpg';
$ok = OSSUploader::uploadFile('r2', 'post_images/', $filename, (string) $canvas->stream('jpeg'));
@@ -216,18 +218,20 @@ public static function handle($post)
// Clone the main image for LQIP version
$lqipImage = clone $canvas;
// Create the LQIP version of the image
$lqipImage->fit(10, 10, function ($constraint) {
$constraint->aspectRatio();
});
// Apply blur
$lqipImage->blur(5); // Adjust to the desired blur level
$lqipImage->encode('jpg', 5);
// Pixelate the image
$lqipImage->pixelate(30); // Adjust this value based on the desired pixelation level
// Encode the image to a low-quality JPG
$lqipImage->encode('webp', 5);
// LQIP filename
$lqip_filename = $post->slug.'-'.epoch_now_timestamp().'_lqip.jpg';
$lqip_filename = $post->slug.'-'.$epoch_now_timestamp.'_lqip.webp';
// Upload the LQIP version using OSSUploader
$lqip_ok = OSSUploader::uploadFile('r2', 'post_images/', $lqip_filename, (string) $lqipImage->stream('jpeg'));
$lqip_ok = OSSUploader::uploadFile('r2', 'post_images/', $lqip_filename, (string) $lqipImage->stream('webp'));
if ($ok && $lqip_ok) {