Skip to content

Commit

Permalink
Fix generateRandomColor() not working
Browse files Browse the repository at this point in the history
  • Loading branch information
miguilimzero committed Nov 3, 2024
1 parent 5f5a1e7 commit ae20d88
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/AntiBotLinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

namespace Miguilim\AntiBotLinks;

use Intervention\Image\Colors\Rgb\Color;
use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Gd\Driver;
use Intervention\Image\Geometry\Factories\LineFactory;
use Intervention\Image\Geometry\Line;
use Intervention\Image\Typography\Font;
use Intervention\Image\Typography\FontFactory;
use Miguilim\AntiBotLinks\CacheAdapters\AbstractCacheAdapter;

Expand Down Expand Up @@ -123,6 +122,7 @@ protected function generateRandomImage(string $word): array
$image = $manager->create($width, $height);

// Add link background
// TODO: Reimplement backgrounds. Not working with current version of InterventionImage.
// if ($this->background) {
// $image->fill($this->asset('backgrounds/bg-' . random_int(1, 3) . '-' . (($this->darkTheme) ? 'l' : 'd') . '.png'));
// // ->brightness(($this->darkTheme) ? mt_rand(5, 15) : mt_rand(55, 75));
Expand Down Expand Up @@ -166,18 +166,20 @@ protected function generateRandomImage(string $word): array
}

/**
* Generate random rgba() color array.
* Generate random rgb() color array.
*/
protected function generateRandomColor(bool $isShadowColor = false): array
protected function generateRandomColor(bool $isShadowColor = false): Color
{
// TODO: Reimplement 4th channel (rgba). Not working with current version of InterventionImage.

if ($this->darkTheme) {
return ($isShadowColor)
? [random_int(1, 80), random_int(1, 80), random_int(1, 80), random_int(45, 100) / 100]
: [random_int(214, 254), random_int(214, 254), random_int(214, 254), random_int(75, 100) / 100];
? new Color(random_int(1, 80), random_int(1, 80), random_int(1, 80))
: new Color(random_int(214, 254), random_int(214, 254), random_int(214, 254));
}

return ($isShadowColor)
? [random_int(174, 254), random_int(174, 254), random_int(174, 254), random_int(75, 100) / 100]
: [random_int(1, 80), random_int(1, 80), random_int(1, 80), random_int(45, 100) / 100];
? new Color(random_int(174, 254), random_int(174, 254), random_int(174, 254))
: new Color(random_int(1, 80), random_int(1, 80), random_int(1, 80));
}
}

0 comments on commit ae20d88

Please sign in to comment.