Skip to content

Commit

Permalink
✨ Add social builder
Browse files Browse the repository at this point in the history
  • Loading branch information
matyo91 committed Sep 8, 2024
1 parent b2e7d35 commit 1418570
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Command/ScrapCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
38 changes: 38 additions & 0 deletions src/Command/SocialBuilderCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace App\Command;

use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

use function sprintf;

#[AsCommand(
name: 'app:social-builder',
description: 'This allow automate your social publications',
)]
class SocialBuilderCommand extends Command
{
protected function execute(InputInterface $input, OutputInterface $output): int
{
$io = new SymfonyStyle($input, $output);
$arg1 = $input->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;
}
}
2 changes: 1 addition & 1 deletion src/Job/ScrapUrlJob.php → src/Job/Scap/ScrapUrlJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Job\FlowExamples;
namespace App\Job\FlowExamples\Scrap;

use App\Model\UrlContent;
use CurlMultiHandle;
Expand Down
2 changes: 1 addition & 1 deletion src/Job/ScrapUrlsJob.php → src/Job/Scap/ScrapUrlsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Job\FlowExamples;
namespace App\Job\FlowExamples\Scrap;

use App\Model\UrlContent;
use Fiber;
Expand Down
56 changes: 56 additions & 0 deletions src/Job/SocialBuilder/SocialBuilderThumbnailJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

declare(strict_types=1);

namespace App\Job\FlowExamples\SocialBuilder;

use Exception;
use Flow\JobInterface;

/**
* @implements JobInterface<string, bool>
*/
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;
}
}

0 comments on commit 1418570

Please sign in to comment.