Skip to content

Commit

Permalink
Merge pull request #294 from teksite/master
Browse files Browse the repository at this point in the history
update to intervention/image v3
  • Loading branch information
mewebstudio authored Aug 6, 2024
2 parents bdc2a2a + 4b3ec12 commit 4b90221
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Captcha for Laravel 5/6/7/8/9/10/11
# Captcha for Laravel 10/11

[![Build Status](https://travis-ci.org/mewebstudio/captcha.svg?branch=master)](https://travis-ci.org/mewebstudio/captcha) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mewebstudio/captcha/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mewebstudio/captcha/?branch=master)
[![Latest Stable Version](https://poser.pugx.org/mews/captcha/v/stable.svg)](https://packagist.org/packages/mews/captcha)
Expand Down Expand Up @@ -39,7 +39,7 @@ project's `composer.json`.
{
"require": {
"laravel/framework": "5.0.*",
"mews/captcha": "~2.0"
"mews/captcha": "~3.0"
},
"minimum-stability": "stable"
}
Expand Down Expand Up @@ -247,4 +247,4 @@ Based on [Intervention Image](https://github.com/Intervention/image)
* [License](http://www.opensource.org/licenses/mit-license.php)
* [Laravel website](http://laravel.com)
* [Laravel Turkiye website](http://www.laravel.gen.tr)
* [MeWebStudio website](http://www.mewebstudio.com)
* [mewebstudio](https://github.com/mewebstudio/captcha)
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"illuminate/support": "~5|^6|^7|^8|^9|^10|^11",
"illuminate/hashing": "~5|^6|^7|^8|^9|^10|^11",
"illuminate/session": "~5|^6|^7|^8|^9|^10|^11",
"intervention/image": "~2.5"
"intervention/image": "^3.7"
},
"require-dev": {
"phpunit/phpunit": "^8.5|^9.5.10|^10.5",
Expand Down
43 changes: 24 additions & 19 deletions src/Captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@
use Illuminate\Hashing\BcryptHasher as Hasher;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Http\File;
use Illuminate\Http\Response;
use Illuminate\Support\Str;
use Intervention\Image\Gd\Font;
use Intervention\Image\Geometry\Factories\LineFactory;
use Intervention\Image\Image;
use Intervention\Image\ImageManager;
use Illuminate\Session\Store as Session;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Http\Response;


/**
* Class Captcha
Expand Down Expand Up @@ -194,6 +198,11 @@ class Captcha
*/
protected $marginTop = 0;

/**
* @var string
*/
protected $fill = 'ccc';

/**
* Constructor
*
Expand Down Expand Up @@ -264,18 +273,15 @@ public function create(string $config = 'default', bool $api = false)
$generator = $this->generate();
$this->text = $generator['value'];

$this->canvas = $this->imageManager->canvas(
$this->width,
$this->height,
$this->bgColor
);
$this->canvas = $this->imageManager->create($this->width , $this->height)->fill($this->fill);


if ($this->bgImage) {
$this->image = $this->imageManager->make($this->background())->resize(
$this->image = $this->imageManager->read($this->background())->resize(
$this->width,
$this->height
);
$this->canvas->insert($this->image);
$this->canvas->place($this->image);
} else {
$this->image = $this->canvas;
}
Expand Down Expand Up @@ -303,8 +309,11 @@ public function create(string $config = 'default', bool $api = false)
return $api ? [
'sensitive' => $generator['sensitive'],
'key' => $generator['key'],
'img' => $this->image->encode('data-url')->encoded
] : $this->image->response('png', $this->quality);
'img' => $this->image->encode()->encoded
] : new Response($this->image->encode(), 200, [
'Content-Type' => 'image/jpeg',
'Content-Disposition' => 'inline; filename="image.jpg"',
]);
}

/**
Expand Down Expand Up @@ -445,16 +454,12 @@ protected function angle(): int
protected function lines()
{
for ($i = 0; $i <= $this->lines; $i++) {
$this->image->line(
rand(0, $this->image->width()) + $i * rand(0, $this->image->height()),
rand(0, $this->image->height()),
rand(0, $this->image->width()),
rand(0, $this->image->height()),
function ($draw) {
/* @var Font $draw */
$draw->color($this->fontColor());
}
);
$this->image->drawLine(function (LineFactory $line) use ($i) {
$line->from(rand(0, $this->image->width()) + $i * rand(0, $this->image->height()) , rand(0, $this->image->height()));
$line->to( rand(0, $this->image->width()), rand(0, $this->image->height()));
$line->color('ff00ff'); // color of line
$line->width(5); // line width in pixels
});
}

return $this->image;
Expand Down

0 comments on commit 4b90221

Please sign in to comment.