Update (Task)
This commit is contained in:
@@ -176,42 +176,46 @@ private static function setPostImage($post)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$main_image_url = $serp_url_research->main_image;
|
|
||||||
$image_ref_url = $serp_url_research->url;
|
|
||||||
|
|
||||||
$image_response = Http::timeout(300)->withHeaders([
|
|
||||||
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
|
|
||||||
])->get($main_image_url);
|
|
||||||
|
|
||||||
$image_content = $image_response->body();
|
|
||||||
|
|
||||||
// Get the size of the image content in KB
|
|
||||||
$imageSizeInKb = strlen($image_response->body()) / 1024;
|
|
||||||
|
|
||||||
// Skip this iteration if the image exceeds the maximum size
|
|
||||||
if ($imageSizeInKb > 1024) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$post_description = strtoupper(now()->format('j M')).' • '.$post->main_keyword.' • '.markdown_min_read($post->body);
|
|
||||||
|
|
||||||
$image = ImageGen::getMainImage($image_content, 1007, 567);
|
|
||||||
$og_image = ImageGen::getOpenGraphImage($image_content, 1007, 567, $post->title, $post_description);
|
|
||||||
|
|
||||||
$epoch_now_timestamp = epoch_now_timestamp();
|
|
||||||
$filename = $post->slug.'-'.$epoch_now_timestamp.'.jpg';
|
|
||||||
$og_filename = $post->slug.'-'.$epoch_now_timestamp.'_og.jpg';
|
|
||||||
|
|
||||||
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/'.$filename;
|
|
||||||
$post->image_ref_url = $image_ref_url;
|
|
||||||
|
|
||||||
$image->destroy();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
$main_image_url = $serp_url_research->main_image;
|
||||||
|
$image_ref_url = $serp_url_research->url;
|
||||||
|
|
||||||
|
$image_response = Http::timeout(300)->withHeaders([
|
||||||
|
'User-Agent' => 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36',
|
||||||
|
])->get($main_image_url);
|
||||||
|
|
||||||
|
$image_content = $image_response->body();
|
||||||
|
|
||||||
|
// Get the size of the image content in KB
|
||||||
|
$imageSizeInKb = strlen($image_response->body()) / 1024;
|
||||||
|
|
||||||
|
// Skip this iteration if the image exceeds the maximum size
|
||||||
|
if ($imageSizeInKb > 1024) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$post_description = strtoupper(now()->format('j M')).' • '.$post->main_keyword.' • '.markdown_min_read($post->body);
|
||||||
|
|
||||||
|
$image = ImageGen::getMainImage($image_content, 1007, 567);
|
||||||
|
$og_image = ImageGen::getOpenGraphImage($image_content, 1007, 567, $post->title, $post_description);
|
||||||
|
|
||||||
|
$epoch_now_timestamp = epoch_now_timestamp();
|
||||||
|
$filename = $post->slug.'-'.$epoch_now_timestamp.'.jpg';
|
||||||
|
$og_filename = $post->slug.'-'.$epoch_now_timestamp.'_og.jpg';
|
||||||
|
|
||||||
|
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/'.$filename;
|
||||||
|
$post->image_ref_url = $image_ref_url;
|
||||||
|
|
||||||
|
$image->destroy();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user