standaniels/image-generator
Composer 安装命令:
composer require standaniels/image-generator
包简介
A package to generate random images.
关键字:
README 文档
README
This package makes generating images easy. Use them for placeholders without being dependent on some external service.
use StanDaniels\ImageGenerator\Canvas; use StanDaniels\ImageGenerator\Color; use StanDaniels\ImageGenerator\Image; use StanDaniels\ImageGenerator\Shape\Shape; $transparency = random_int(60, 80) / 100; $canvas = Canvas::create(400, 400, 2) ->background(Color::random($transparency)); for ($i = random_int(100, 150); $i > 0; $i--) { $transparency = random_int(60, 80) / 100; Shape::random($canvas, Color::random($transparency))->draw(); } // By default, the image is stored in the directory used for temporary files $image = Image::create($canvas);
Of which this could be the output:
Using color palettes
If you would like to generate an image based on a given set of colors like the one below, you can do it like this.
use StanDaniels\ImageGenerator\Canvas; use StanDaniels\ImageGenerator\Color; use StanDaniels\ImageGenerator\Image; use StanDaniels\ImageGenerator\Shape\Shape; $colors = [ new Color(73, 78, 109), new Color(214, 119, 98), new Color(144, 180, 148), new Color(237, 203, 150), new Color(136, 80, 83), ]; $canvas = Canvas::create(400, 400, 2) ->background(new Color(34, 36, 50)); for ($i = random_int(50, 100); $i > 0; $i--) { $color = clone $colors[random_int(0, count($colors) - 1)]; $color->setAlpha(random_int(50, 60) / 100); Shape::random($canvas, $color)->draw(); } $image = Image::create($canvas);
The output would be something like this:
Installation
The library is distributed as a C extension. You compile it once against your local PHP installation, then load it like any other .so extension.
Requirements
| Requirement | Notes |
|---|---|
| PHP ≥ 8.0 | Tested through PHP 8.5 |
| php-dev / php-devel | Provides phpize and the build headers |
| libgd | PHP must be built with GD support (ext-gd) |
| libexif | PHP must be built with EXIF support (ext-exif) |
| A C compiler | gcc or clang |
| make | Standard build tool |
On Debian / Ubuntu:
sudo apt-get install php-dev php-gd php-exif build-essential
On Red Hat / Fedora / CentOS:
sudo dnf install php-devel php-gd php-exif gcc make
On macOS (with Homebrew):
brew install php
# php-config, phpize, and gd are included in the Homebrew php formula
Build and install
The C source lives in the ext/ directory.
cd ext/ # 1. Prepare the build environment phpize # 2. Configure (links against your active PHP installation automatically) ./configure # 3. Compile make # 4. Install the .so into your PHP extension directory sudo make install
make install copies image_generator.so to the directory shown by php-config --extension-dir.
Enable the extension
Add the extension to your php.ini:
extension=image_generator
Find the right php.ini with:
php --ini
To enable it only for a single script without editing php.ini:
php -d extension=image_generator script.php
Verify the installation
php -r "var_dump(extension_loaded('image_generator'));" # → bool(true)
Run the test suite
The PHPT tests in ext/tests/ are run with PHP's built-in test runner. From inside the ext/ directory (after make):
make test
Or run them directly against the freshly built .so:
php run-tests.php -d extension=modules/image_generator.so tests/
License
The MIT License (MIT). Please see License File for more information.
standaniels/image-generator 适用场景与选型建议
standaniels/image-generator 是一款 基于 C 开发的 Composer 扩展包,目前已累计 99.57k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2018 年 08 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「generator」 「image」 「random」 「stan」 「daniels」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 standaniels/image-generator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 standaniels/image-generator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 standaniels/image-generator 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
Yii2 LightBox image galary widget uses Lightbox v2.10.0 by Lokesh Dhakar
The Yii2 extension uses jQuery jquery.carousel-1.1.min.js and makes image carousel from php array of structure defined.
Faker Japanese is a Faker provider that generates fake Japanese related data for you.
Gambling Algorithms for Certification.
The Yii2 extension uses jQuery PrettyPhoto and OwlCarousel js and makes image galary from php array of structure defined.
统计信息
- 总下载量: 99.57k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 16
- 点击次数: 22
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-08-19


