PHPackages                             haileyji/think-glide - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. haileyji/think-glide

ActiveLibrary[Image &amp; Media](/categories/media)

haileyji/think-glide
====================

ThinkPHP8 adapter for using Glide image manipulation library

2.x-dev(2y ago)02MITPHPPHP &gt;=7.2.0

Since Nov 6Pushed 2y agoCompare

[ Source](https://github.com/haileyji/think-glide)[ Packagist](https://packagist.org/packages/haileyji/think-glide)[ RSS](/packages/haileyji-think-glide/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelogDependencies (3)Versions (1)Used By (0)

ThinkPHP6+ 图片动态裁剪缩放库
====================

[](#thinkphp6-图片动态裁剪缩放库)

[Glide](https://github.com/thephpleague/glide) 是一个可以帮助你根据指定参数动态的生成图片内容给浏览器的图片操作库，从而实现 图片动态裁剪，打水印等，本库对 Glide 进行了一些友好的包装与扩展，屏蔽了原生库的一些底层抽象从而使得 ThinkPHP 用户可以在 ThinkPHP6 项目中 更好的添加图片的动态裁剪功能。

Installation
------------

[](#installation)

执行下面命令安装:

```
$ composer require yzh52521/think-glide
```

Usage
-----

[](#usage)

### Quick start

[](#quick-start)

- ThinkPHP6 及以上版本使用 middleware 注册：

    打开 `application/middleware.php` 文件（如果不存在创建即可），注册 middleware：

    ```
    return [
        //...

        \think\glide\middleware\Glide::class
    ];
    ```

### 生成配置

[](#生成配置)

系统安装后会自动在 config 目录中生成 glide.php 的配置文件， 如果系统未生成可在命令行执行

```
php think glide:config
```

快速生成配置文件

### 参数说明

[](#参数说明)

参数名类型说明是否必选sourcestring本地文件夹位置是cachestring缓存文件位置，默认在 `runtime/glide` 下面否cacheTimestring缓存时间，示例 `+2 days`, 缓存期间多次请求会自动响应 304否signKeystring安全签名否onExceptioncallable异常处理handler否baseUrlstring路由前缀，匹配到该前缀时中间件开始执行，默认是 `/images`否`source` 是你本地图片文件夹的位置，假设该目录下有图片 `user.jpg`, 打开浏览器访问下面链接：

```
http://youdomain.com/images/user.jpg?w=100&h=100

```

即可得到缩小后的图片。

### 安全签名

[](#安全签名)

不开启安全签名的情况下用户可以调整query里面的参数自行对图片进行裁剪，如果你不打算这么做的话，你可以通过 `signKey` 进行校验，

这种情况下用户自行调整参数将会无效；生成安全的URL:

```
echo glide_url('user.jpg', ['w' => 100, 'h' => 100]);
或
echo app('glide_builder')->getUrl('user.jpg', ['w' => 100, 'h' => 100]);

//你会得到如下链接：/images/user.jpg?w=100&h=100&sign=af3dc18fc6bfb2afb521e587c348b904
```

### 异常处理

[](#异常处理)

如果用户访问了一张不存在的图片或者没有进行安全校验，系统会抛出异常，你可以通过修改配置文件中 `onException` 进行替换默认行为：

```
return [
    //...

    'onException' => function(\Exception $exception, $request, $server){

        if ($exception instanceof \League\Glide\Signatures\SignatureException) {
            $response = response('签名错误', 403);
        } else {
            $response = response(sprintf('你访问的资源 "%s" 不存在', $request->path()), 404);
        }

        return $response;
    }
])
```

#### nginx 配置

[](#nginx-配置)

```
location ~* /images/(.*)$ {
  try_files $uri $uri/ /index.php/$request_uri;
}

```

注意该闭包必须返回一个 `think\Response` 实例；

### Quick reference

[](#quick-reference)

不止支持裁剪，glide还支持其它操作，只要传递对应参数即可，参考这里查看支持的参数：

License
-------

[](#license)

See [MIT](https://opensource.org/licenses/MIT).

###  Health Score

13

—

LowBetter than 1% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

919d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a9bf7dc1fd67191c912f1244a4c2bddc09b662940cbb7105b73a2d9acac38290?d=identicon)[haileyji](/maintainers/haileyji)

---

Top Contributors

[![yuanzhihai](https://avatars.githubusercontent.com/u/15060466?v=4)](https://github.com/yuanzhihai "yuanzhihai (8 commits)")

---

Tags

glidethinkphpthink-glide

### Embed Badge

![Health badge](/badges/haileyji-think-glide/health.svg)

```
[![Health](https://phpackages.com/badges/haileyji-think-glide/health.svg)](https://phpackages.com/packages/haileyji-think-glide)
```

###  Alternatives

[awcodes/filament-curator

A media picker plugin for FilamentPHP.

434297.7k19](/packages/awcodes-filament-curator)[trntv/yii2-glide

Yii2 Glide Extension

41269.5k9](/packages/trntv-yii2-glide)[admad/cakephp-glide

CakePHP plugin for using Glide image manipulation library.

34160.7k1](/packages/admad-cakephp-glide)[ralphjsmit/laravel-glide

Auto-magically generate responsive images from static image files.

4719.6k5](/packages/ralphjsmit-laravel-glide)[frozzare/wp-glide

Simple integration of Glide with WordPress

185.3k](/packages/frozzare-wp-glide)[infinityweb/glide-optimizer

An optimizer manipulator for Glide that uses ps/image-optimizer package.

1011.1k](/packages/infinityweb-glide-optimizer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
