Detailed explanation of how to implement rotated image verification in PHP

藏色散人
Release: 2023-04-11 09:44:01
forward
4489 people have browsed it

This article brings you relevant knowledge about PHP. It mainly introduces how PHP implements rotation image verification. Let’s take a look at it together. I hope it will be helpful to everyone.

Detailed explanation of how to implement rotated image verification in PHP

Installation

composer require kkokk/poster
Copy after login

Update

composer update kkokk/poster
Copy after login

Use documentation

Open source repository:
gitee documentation
github document

    use Kkokk\Poster\PosterManager;
    use Kkokk\Poster\Exception\PosterException;

    try {
        # 旋转图片自定义参数
        $params = [
            'src'           => '',  // 背景图片,尺寸 350 * 350 正方形都可
            'im_width'      => 350, // 画布宽度
            'im_height'     => 350, // 画布高度
        ];

        $type = 'rotate';

        /**
          * 获取验证参数
          * 内部使用了 laravel 的 cache 缓存,返回的是图片的 base64 、 缓存key
          * @param string $type   验证码类型
          * @param array  $params 验证码自定义参数
          * @return arary
          */
        $data = PosterManager::Captcha()->type($type)->config($params)->get();

        /**
          * 验证
          * 前端根据相关Detailed explanation of how to implement rotated image verification in PHP操作进行处理, 返回旋转角度,返回 true 则验证成功
          * @param string     $key     缓存key
          * @param string|int $value   前端传回来的旋转角度
          * @param int        $leeway  误差值
          * @return boolean
          */
        $res = PosterManager::Captcha()->type($type)->check($key, $value, $leeway);

    } catch (PosterException $e) {
        print_r($e->getMessage())
    }
Copy after login

Example

ui imitation Baidu statistics
Detailed explanation of how to implement rotated image verification in PHP

Recommended study:《PHP video tutorial

The above is the detailed content of Detailed explanation of how to implement rotated image verification in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!