diff --git a/src/Command/ScrapCommand.php b/src/Command/ScrapCommand.php index 5dbc777..aa669f5 100644 --- a/src/Command/ScrapCommand.php +++ b/src/Command/ScrapCommand.php @@ -4,8 +4,8 @@ namespace App\Command; -use App\Job\FlowExamples\ScrapUrlJob; -use App\Job\FlowExamples\ScrapUrlsJob; +use App\Job\FlowExamples\Scrap\ScrapUrlJob; +use App\Job\FlowExamples\Scrap\ScrapUrlsJob; use App\Model\UrlContent; use Fiber; use Flow\AsyncHandler\DeferAsyncHandler; diff --git a/src/Command/SocialBuilderCommand.php b/src/Command/SocialBuilderCommand.php new file mode 100644 index 0000000..d0ab9ce --- /dev/null +++ b/src/Command/SocialBuilderCommand.php @@ -0,0 +1,38 @@ +getArgument('arg1'); + + if ($arg1) { + $io->note(sprintf('You passed an argument: %s', $arg1)); + } + + if ($input->getOption('option1')) { + // ... + } + + $io->success('You have a new command! Now make it your own! Pass --help to see your options.'); + + return Command::SUCCESS; + } +} diff --git a/src/Job/ScrapUrlJob.php b/src/Job/Scap/ScrapUrlJob.php similarity index 97% rename from src/Job/ScrapUrlJob.php rename to src/Job/Scap/ScrapUrlJob.php index 2eba5f5..f211029 100644 --- a/src/Job/ScrapUrlJob.php +++ b/src/Job/Scap/ScrapUrlJob.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Job\FlowExamples; +namespace App\Job\FlowExamples\Scrap; use App\Model\UrlContent; use CurlMultiHandle; diff --git a/src/Job/ScrapUrlsJob.php b/src/Job/Scap/ScrapUrlsJob.php similarity index 97% rename from src/Job/ScrapUrlsJob.php rename to src/Job/Scap/ScrapUrlsJob.php index 2d5d6a6..beaf234 100644 --- a/src/Job/ScrapUrlsJob.php +++ b/src/Job/Scap/ScrapUrlsJob.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace App\Job\FlowExamples; +namespace App\Job\FlowExamples\Scrap; use App\Model\UrlContent; use Fiber; diff --git a/src/Job/SocialBuilder/SocialBuilderThumbnailJob.php b/src/Job/SocialBuilder/SocialBuilderThumbnailJob.php new file mode 100644 index 0000000..5281d62 --- /dev/null +++ b/src/Job/SocialBuilder/SocialBuilderThumbnailJob.php @@ -0,0 +1,56 @@ + + */ +class SocialBuilderThumbnailJob implements JobInterface +{ + public function __invoke($data): bool + { + // Define the path where the generated image will be saved + $imagePath = __DIR__ . '/thumbnail.png'; + + // Create an image with width 400px and height 300px + $width = 400; + $height = 300; + $image = imagecreatetruecolor($width, $height); + + // Set background color (white) + $backgroundColor = imagecolorallocate($image, 255, 255, 255); + imagefilledrectangle($image, 0, 0, $width, $height, $backgroundColor); + + // Set text color (black) + $textColor = imagecolorallocate($image, 0, 0, 0); + + // Add the input string text to the image + $fontPath = __DIR__ . '/arial.ttf'; // Ensure this is a valid font path + $fontSize = 12; + $angle = 0; + $x = 10; + $y = 50; + + // If a TTF font file exists, use it; otherwise, fall back to a built-in font + if (file_exists($fontPath)) { + imagettftext($image, $fontSize, $angle, $x, $y, $textColor, $fontPath, $data); + } else { + imagestring($image, 5, $x, $y, $data, $textColor); + } + + // Save the image to the defined path + if (!imagepng($image, $imagePath)) { + throw new Exception('Failed to save the generated image.'); + } + + // Free up memory + imagedestroy($image); + + return true; + } +}