Add (tint)

This commit is contained in:
2023-11-21 01:21:30 +08:00
parent 7166eb610c
commit e4bab8dcec
48 changed files with 229 additions and 58 deletions

View File

@@ -2,6 +2,7 @@
namespace App\Jobs\Tasks;
use App\Helpers\FirstParty\ImageGen\ImageGen;
use App\Helpers\FirstParty\OpenAI\OpenAI;
use App\Helpers\FirstParty\OSSUploader\OSSUploader;
use App\Jobs\SchedulePublishPost;
@@ -184,6 +185,7 @@ private static function setPostImage($post)
$image_content = $image_response->body();
// Get the size of the image content in KB
$imageSizeInKb = strlen($image_response->body()) / 1024;
@@ -192,49 +194,20 @@ private static function setPostImage($post)
continue;
}
$canvas_width = 1080;
$canvas_height = 608;
$post_description = strtoupper(now()->format('j M')) . "" . $post->main_keyword . "" . markdown_min_read($post->body);
$thumb_width = 540;
$thumb_height = 78;
$image = ImageGen::getMainImage($image_content, 1007, 567);
$og_image = ImageGen::getOpenGraphImage($image_content, 1007, 567, $post->title, $post_description);
// Create an image from the fetched content
$image = Image::make($image_content);
// Check if the image is wider than it is tall (landscape orientation)
if ($image->width() > $image->height()) {
// Resize the image to fill the canvas width while maintaining aspect ratio
$image->resize($canvas_width, null, function ($constraint) {
$constraint->aspectRatio();
});
} else {
// Resize the image to fill the canvas height while maintaining aspect ratio
$image->resize(null, $canvas_height, function ($constraint) {
$constraint->aspectRatio();
});
}
// Fit the image to the canvas size, without gaps
$image->fit($canvas_width, $canvas_height, function ($constraint) {
$constraint->upsize();
});
// Create a thumbnail by cloning the original image and resizing it
$thumb = clone $image;
$thumb->resize($thumb_width, $thumb_height, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
// Create a image filename
$epoch_now_timestamp = epoch_now_timestamp();
$filename = $post->slug.'-'.$epoch_now_timestamp.'.jpg';
$thumb_filename = $post->slug.'-'.$epoch_now_timestamp.'_thumb.jpg';
$og_filename = $post->slug.'-'.$epoch_now_timestamp.'_og.jpg';
OSSUploader::uploadFile('r2', 'post_images_2/', $filename, (string) $image->stream('jpeg', 75));
OSSUploader::uploadFile('r2', 'post_images_2/', $thumb_filename, (string) $thumb->stream('jpeg', 50));
OSSUploader::uploadFile('r2', 'post_images/', $filename, (string) $image->stream('jpeg', 75));
OSSUploader::uploadFile('r2', 'post_images/', $og_filename, (string) $og_image->stream('jpeg', 75));
$post->featured_image = 'post_images_2/'.$filename;
$post->featured_image = 'post_images/'.$filename;
$post->image_ref_url = $image_ref_url;
$image->destroy();