Add (tint)
This commit is contained in:
@@ -8,164 +8,162 @@ class ImageGen
|
||||
{
|
||||
public static function getMainImage($url, $width, $height)
|
||||
{
|
||||
$canvas = self::getBaseImage($url, 2.0, $width, $height);
|
||||
$canvas = self::getBaseImage($url, 2.0, $width, $height);
|
||||
|
||||
$canvas = self::setImageTint($canvas, $width, $height);
|
||||
$canvas = self::setImageTint($canvas, $width, $height);
|
||||
|
||||
return $canvas;
|
||||
return $canvas;
|
||||
}
|
||||
|
||||
public static function getOpenGraphImage($url, $width, $height, $title = 'Title', $description = 'Description', $website = 'WWW.FUTUREWALKER.CO')
|
||||
{
|
||||
$canvas = self::getBaseImage($url, 2.0, $width, $height);
|
||||
$canvas = self::getBaseImage($url, 2.0, $width, $height);
|
||||
|
||||
$canvas = self::setImageTint($canvas, $width, $height);
|
||||
$canvas = self::setImageTint($canvas, $width, $height);
|
||||
|
||||
$canvas = self::setOgTint($canvas, $width, $height);
|
||||
$canvas = self::setOgTint($canvas, $width, $height);
|
||||
|
||||
$canvas = self::setOgText($canvas, $title, $description, $website);
|
||||
$canvas = self::setOgText($canvas, $title, $description, $website);
|
||||
|
||||
return $canvas;
|
||||
return $canvas;
|
||||
}
|
||||
|
||||
private static function setOgText($canvas, $title, $description, $website)
|
||||
{
|
||||
$bold_font = resource_path('fonts/RobotoCondensed/RobotoCondensed-Bold.ttf');
|
||||
$font_color = '#ffffff'; // White color for the text
|
||||
private static function setOgText($canvas, $title, $description, $website)
|
||||
{
|
||||
$bold_font = resource_path('fonts/RobotoCondensed/RobotoCondensed-Bold.ttf');
|
||||
$font_color = '#ffffff'; // White color for the text
|
||||
|
||||
// Define font sizes
|
||||
$font_size_title = 65; // Size of the title text
|
||||
$font_size_description = 28; // Size of the description text
|
||||
$font_size_website = 28; // Size of the website text
|
||||
// Define font sizes
|
||||
$font_size_title = 65; // Size of the title text
|
||||
$font_size_description = 28; // Size of the description text
|
||||
$font_size_website = 28; // Size of the website text
|
||||
|
||||
// Define positions
|
||||
$title_position_y = $canvas->height() - 145; // Position for the title at one-third the height
|
||||
$description_position_y = $canvas->height() - 30;
|
||||
$website_position_y = $canvas->height() - 30;
|
||||
// Define positions
|
||||
$title_position_y = $canvas->height() - 145; // Position for the title at one-third the height
|
||||
$description_position_y = $canvas->height() - 30;
|
||||
$website_position_y = $canvas->height() - 30;
|
||||
|
||||
// Title - wrapped to 2 lines if necessary, with ellipsis if there is excess text
|
||||
$wrappedTitle = wordwrap($title, 35, "\n", true); // Wrap the title
|
||||
$lines = explode("\n", $wrappedTitle); // Split the title into lines
|
||||
// Title - wrapped to 2 lines if necessary, with ellipsis if there is excess text
|
||||
$wrappedTitle = wordwrap($title, 35, "\n", true); // Wrap the title
|
||||
$lines = explode("\n", $wrappedTitle); // Split the title into lines
|
||||
|
||||
// Adjust these variables as needed
|
||||
$lineHeight = 65; // The height of a line of text, adjust as needed for line spacing
|
||||
$titleStartPositionY = $title_position_y; // Starting Y position for the title, adjust if needed
|
||||
// Adjust these variables as needed
|
||||
$lineHeight = 65; // The height of a line of text, adjust as needed for line spacing
|
||||
$titleStartPositionY = $title_position_y; // Starting Y position for the title, adjust if needed
|
||||
|
||||
// Check if there are more than 2 lines after wrapping
|
||||
if (count($lines) > 2) {
|
||||
$lines = array_slice($lines, 0, 2); // Keep only the first two lines
|
||||
$secondLine = &$lines[1]; // Reference to the second line
|
||||
// Check if the second line can fit an ellipsis; if not, trim the text
|
||||
if (strlen($secondLine) > 32) {
|
||||
$secondLine = substr($secondLine, 0, 32) . '...'; // Trim and add ellipsis
|
||||
} else {
|
||||
// Add ellipsis directly if there's enough space
|
||||
$secondLine .= '...';
|
||||
// Check if there are more than 2 lines after wrapping
|
||||
if (count($lines) > 2) {
|
||||
$lines = array_slice($lines, 0, 2); // Keep only the first two lines
|
||||
$secondLine = &$lines[1]; // Reference to the second line
|
||||
// Check if the second line can fit an ellipsis; if not, trim the text
|
||||
if (strlen($secondLine) > 32) {
|
||||
$secondLine = substr($secondLine, 0, 32).'...'; // Trim and add ellipsis
|
||||
} else {
|
||||
// Add ellipsis directly if there's enough space
|
||||
$secondLine .= '...';
|
||||
}
|
||||
}
|
||||
|
||||
// Now, render each line individually with adjusted line spacing
|
||||
foreach ($lines as $index => $line) {
|
||||
$currentLineY = $titleStartPositionY + ($index * $lineHeight);
|
||||
$canvas->text($line, 30, $currentLineY, function ($font) use ($bold_font, $font_color, $font_size_title) {
|
||||
$font->file($bold_font);
|
||||
$font->size($font_size_title);
|
||||
$font->color($font_color);
|
||||
$font->align('left'); // Align text to the left
|
||||
$font->valign('bottom'); // Align text to the top of the current line position
|
||||
});
|
||||
}
|
||||
|
||||
// Description - justified to the left, below the title
|
||||
$canvas->text($description, 30, $description_position_y, function ($font) use ($bold_font, $font_color, $font_size_description) {
|
||||
$font->file($bold_font);
|
||||
$font->size($font_size_description);
|
||||
$font->color($font_color);
|
||||
$font->align('left'); // Align text to the left
|
||||
$font->valign('bottom'); // Align text to the top (as it is below the title)
|
||||
});
|
||||
|
||||
// Website - justified to the right, at the bottom of the image
|
||||
$canvas->text($website, $canvas->width() - 30, $website_position_y, function ($font) use ($bold_font, $font_color, $font_size_website) {
|
||||
$font->file($bold_font);
|
||||
$font->size($font_size_website);
|
||||
$font->color($font_color);
|
||||
$font->align('right'); // Align text to the right
|
||||
$font->valign('bottom'); // Align text to the bottom
|
||||
});
|
||||
|
||||
return $canvas;
|
||||
}
|
||||
}
|
||||
|
||||
// Now, render each line individually with adjusted line spacing
|
||||
foreach ($lines as $index => $line) {
|
||||
$currentLineY = $titleStartPositionY + ($index * $lineHeight);
|
||||
$canvas->text($line, 30, $currentLineY, function($font) use ($bold_font, $font_color, $font_size_title) {
|
||||
$font->file($bold_font);
|
||||
$font->size($font_size_title);
|
||||
$font->color($font_color);
|
||||
$font->align('left'); // Align text to the left
|
||||
$font->valign('bottom'); // Align text to the top of the current line position
|
||||
});
|
||||
}
|
||||
|
||||
// Description - justified to the left, below the title
|
||||
$canvas->text($description, 30, $description_position_y, function($font) use ($bold_font, $font_color, $font_size_description) {
|
||||
$font->file($bold_font);
|
||||
$font->size($font_size_description);
|
||||
$font->color($font_color);
|
||||
$font->align('left'); // Align text to the left
|
||||
$font->valign('bottom'); // Align text to the top (as it is below the title)
|
||||
});
|
||||
|
||||
// Website - justified to the right, at the bottom of the image
|
||||
$canvas->text($website, $canvas->width() - 30, $website_position_y, function($font) use ($bold_font, $font_color, $font_size_website) {
|
||||
$font->file($bold_font);
|
||||
$font->size($font_size_website);
|
||||
$font->color($font_color);
|
||||
$font->align('right'); // Align text to the right
|
||||
$font->valign('bottom'); // Align text to the bottom
|
||||
});
|
||||
|
||||
return $canvas;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static function setOgTint($canvas, $width, $height)
|
||||
{
|
||||
|
||||
$og_tint = Image::make(resource_path("images/tints/caption-bg.png"));
|
||||
$og_tint = Image::make(resource_path('images/tints/caption-bg.png'));
|
||||
|
||||
// Stretch the image to the given width and height
|
||||
$og_tint->resize($width, $height);
|
||||
// Stretch the image to the given width and height
|
||||
$og_tint->resize($width, $height);
|
||||
|
||||
$canvas->insert($og_tint, 'top-left', 0, 0);
|
||||
$canvas->insert($og_tint, 'top-left', 0, 0);
|
||||
|
||||
return $canvas;
|
||||
return $canvas;
|
||||
}
|
||||
|
||||
private static function setImageTint($canvas, $width, $height)
|
||||
{
|
||||
/// ADD TINT
|
||||
// Define the directory path
|
||||
$directoryPath = resource_path('images/tints');
|
||||
/// ADD TINT
|
||||
// Define the directory path
|
||||
$directoryPath = resource_path('images/tints');
|
||||
|
||||
// Search for files starting with 'tint-' and count them
|
||||
$tintFilesCount = count(glob($directoryPath . '/tint-*'));
|
||||
// Search for files starting with 'tint-' and count them
|
||||
$tintFilesCount = count(glob($directoryPath.'/tint-*'));
|
||||
|
||||
$tint_image = Image::make(resource_path("images/tints/tint-" . rand(1, $tintFilesCount) . ".png"));
|
||||
$tint_image = Image::make(resource_path('images/tints/tint-'.rand(1, $tintFilesCount).'.png'));
|
||||
|
||||
// Stretch the image to the given width and height
|
||||
$tint_image->resize($width, $height);
|
||||
// Stretch the image to the given width and height
|
||||
$tint_image->resize($width, $height);
|
||||
|
||||
$canvas->insert($tint_image, 'top-left', 0, 0);
|
||||
$canvas->insert($tint_image, 'top-left', 0, 0);
|
||||
|
||||
return $canvas;
|
||||
return $canvas;
|
||||
}
|
||||
|
||||
private static function getBaseImage($url, $scale = 1.8, $width = 1007, $height = 567)
|
||||
{
|
||||
$original_image = Image::make($url);
|
||||
$original_image = Image::make($url);
|
||||
|
||||
// Determine which dimension (width or height) is larger
|
||||
if ($original_image->width() > $original_image->height()) {
|
||||
// Width is larger, resize by width
|
||||
$original_image->resize($width, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize(); // Prevent upscaling
|
||||
});
|
||||
} else {
|
||||
// Height is larger or equal, resize by height
|
||||
$original_image->resize(null, $height, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize(); // Prevent upscaling
|
||||
});
|
||||
}
|
||||
// Determine which dimension (width or height) is larger
|
||||
if ($original_image->width() > $original_image->height()) {
|
||||
// Width is larger, resize by width
|
||||
$original_image->resize($width, null, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize(); // Prevent upscaling
|
||||
});
|
||||
} else {
|
||||
// Height is larger or equal, resize by height
|
||||
$original_image->resize(null, $height, function ($constraint) {
|
||||
$constraint->aspectRatio();
|
||||
$constraint->upsize(); // Prevent upscaling
|
||||
});
|
||||
}
|
||||
|
||||
// Scale the image by 1.5x
|
||||
$scaled_width = $original_image->width() * $scale;
|
||||
$scaled_height = $original_image->height() * $scale;
|
||||
$original_image->resize($scaled_width, $scaled_height);
|
||||
// Scale the image by 1.5x
|
||||
$scaled_width = $original_image->width() * $scale;
|
||||
$scaled_height = $original_image->height() * $scale;
|
||||
$original_image->resize($scaled_width, $scaled_height);
|
||||
|
||||
// Create an empty canvas
|
||||
$canvas = Image::canvas($width, $height);
|
||||
// Create an empty canvas
|
||||
$canvas = Image::canvas($width, $height);
|
||||
|
||||
// Calculate the position to center the scaled image
|
||||
$x = ($canvas->width() - $scaled_width) / 2;
|
||||
$y = ($canvas->height() - $scaled_height) / 2;
|
||||
// Calculate the position to center the scaled image
|
||||
$x = ($canvas->width() - $scaled_width) / 2;
|
||||
$y = ($canvas->height() - $scaled_height) / 2;
|
||||
|
||||
// Paste the scaled image onto the canvas at the center position
|
||||
// Paste the scaled image onto the canvas at the center position
|
||||
|
||||
$canvas->insert($original_image, 'top-left', (int) $x, (int) $y);
|
||||
$canvas->insert($original_image, 'top-left', (int) $x, (int) $y);
|
||||
|
||||
return $canvas;
|
||||
return $canvas;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,13 +34,12 @@ public function search(Request $request)
|
||||
|
||||
// Use full-text search capabilities of your database
|
||||
// For example, using MySQL's full-text search with MATCH...AGAINST
|
||||
$posts = Post::with('category')
|
||||
->where('status', 'publish')
|
||||
->whereRaw("to_tsvector('english', title || ' ' || bites) @@ to_tsquery('english', ?)", [str_replace(' ', ' & ', $query)])
|
||||
->where('published_at', '<=', now())
|
||||
->orderBy('published_at', 'desc')
|
||||
->cursorPaginate(10);
|
||||
|
||||
$posts = Post::with('category')
|
||||
->where('status', 'publish')
|
||||
->whereRaw("to_tsvector('english', title || ' ' || bites) @@ to_tsquery('english', ?)", [str_replace(' ', ' & ', $query)])
|
||||
->where('published_at', '<=', now())
|
||||
->orderBy('published_at', 'desc')
|
||||
->cursorPaginate(10);
|
||||
|
||||
// breadcrumb json ld
|
||||
$listItems = [];
|
||||
|
||||
@@ -2,23 +2,22 @@
|
||||
|
||||
namespace App\Http\Controllers\Tests;
|
||||
|
||||
use App\Helpers\FirstParty\ImageGen\ImageGen;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow;
|
||||
use LaravelGoogleIndexing;
|
||||
use App\Helpers\FirstParty\ImageGen\ImageGen;
|
||||
|
||||
|
||||
class TestController extends Controller
|
||||
{
|
||||
public function imageGen(Request $request)
|
||||
{
|
||||
$image_url = 'https://cdn.futurewalker.co/post_images_2/whats-next-for-openai-after-ceo-sam-altmans-ouster-1700439234754.jpg';
|
||||
$image_url = 'https://cdn.futurewalker.co/post_images_2/whats-next-for-openai-after-ceo-sam-altmans-ouster-1700439234754.jpg';
|
||||
|
||||
$canvas = ImageGen::getOpenGraphImage($image_url, 'What’s Next for OpenAI After CEO Sam Altman’s Ouster What’s Next for OpenAI After CEO Sam Altman’s Ouster', '20 NOV • OPENAI • SAM ALTMAN • 3 min read ');
|
||||
$canvas = ImageGen::getOpenGraphImage($image_url, 'What’s Next for OpenAI After CEO Sam Altman’s Ouster What’s Next for OpenAI After CEO Sam Altman’s Ouster', '20 NOV • OPENAI • SAM ALTMAN • 3 min read ');
|
||||
|
||||
return response($canvas->encode('jpeg'))
|
||||
->header('Content-Type', 'image/jpeg');
|
||||
return response($canvas->encode('jpeg'))
|
||||
->header('Content-Type', 'image/jpeg');
|
||||
}
|
||||
|
||||
public function indexing(Request $request)
|
||||
|
||||
@@ -185,7 +185,6 @@ 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;
|
||||
|
||||
@@ -194,12 +193,11 @@ private static function setPostImage($post)
|
||||
continue;
|
||||
}
|
||||
|
||||
$post_description = strtoupper(now()->format('j M')) . " • " . $post->main_keyword . " • " . markdown_min_read($post->body);
|
||||
$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';
|
||||
|
||||
@@ -51,9 +51,8 @@ public static function handle(NewsSerpResult $news_serp_result, $serp_counts = 1
|
||||
|
||||
// check timestamp
|
||||
$serp_timestamp = Carbon::parse($serp_item->timestamp);
|
||||
if(!$serp_timestamp->isBetween(now()->subHours(6), now()))
|
||||
{
|
||||
continue;
|
||||
if (! $serp_timestamp->isBetween(now()->subHours(6), now())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/////
|
||||
@@ -64,9 +63,6 @@ public static function handle(NewsSerpResult $news_serp_result, $serp_counts = 1
|
||||
|
||||
$skipItem = false;
|
||||
|
||||
|
||||
|
||||
|
||||
foreach ($blacklist_domains as $domain) {
|
||||
if (str_contains($serp_item->domain, $domain)) {
|
||||
$skipItem = true;
|
||||
|
||||
@@ -31,7 +31,7 @@ public function boot(): void
|
||||
$this->routes(function () {
|
||||
Route::middleware('web')
|
||||
->prefix('tests')
|
||||
->group(base_path('routes/tests.php'));
|
||||
->group(base_path('routes/tests.php'));
|
||||
Route::middleware('api')
|
||||
->prefix('api')
|
||||
->group(base_path('routes/api.php'));
|
||||
|
||||
Reference in New Issue
Block a user