abdullah-karam/laravel-svg
Composer 安装命令:
composer require abdullah-karam/laravel-svg
包简介
this package is about generating svg according to any string containing two words with some pretty options
README 文档
README
Laravel SVG
A Laravel package for generating SVG images from user full names or initials with some pretty cool customization options.
Requirements
- This package requires PHP 8.0 or higher.
Installation
You can install the package via Composer by running the following command:
composer require abdullah-karam/laravel-svg
Usage
example (1)
To generate an SVG image from a user's full name, you can use the svgFor() method on the LaravelSvg facade.
The svgFor() method accepts a single parameter, which is the user's full name. Here's an example of how you might use
the svgFor() method:
<?php namespace App\Http\Controllers; use Abdullah\LaravelSvg\Facades\LaravelSvg; use App\Models\User; class UserController extends Controller { public function generateSvg(User $user) { $svgDetails = LaravelSvg::svgFor(words: $user->fullname)->generate(); dd($svgDetails); } }
This will generate an SVG image with the user's initials in the center.
array:6 [▼ "name" => "64af002c8ba51.svg" "path" => "users/64af002c8ba51.svg" "full_path" => "http://localhost:8000/storage/users/64af002c8ba51.svg" "mime_type" => "image/svg+xml" "size" => 422 "disk" => "public" ]
example (2)
You can also generate an SVG image from a user's initials with logo text by using the svgFor() method on the
LaravelSvg facade. The svgFor() method accepts a single parameter, which is the user's initials and chain with method logoText(). Here's an example of how you might use
<?php namespace App\Http\Controllers; use Abdullah\LaravelSvg\Facades\LaravelSvg; use App\Models\User; class UserController extends Controller { public function generateSvg(User $user) { $svgDetails = LaravelSvg::svgFor(words: $user->fullname) ->logoText()->generate(); dd($svgDetails); } }
This will generate an SVG image with the user's initials in the center and logo text.
with default logo text. if you want to change logo text you can use logoText() method with parameter.
like this logoText('logo') or define it once in config/laravel-svg.php file.
array:6 [▼ "name" => "64af03da5f35c.svg" "path" => "users/64af03da5f35c.svg" "full_path" => "http://localhost:8000/storage/users/64af03da5f35c.svg" "mime_type" => "image/svg+xml" "size" => 414 "disk" => "public" ]
Configuration
You can publish the configuration file using this command:
php artisan vendor:publish --provider="Abdullah\LaravelSvg\LaravelSvgServiceProvider" --tag="config"
This is the contents of the published config file:
<?php return [ 'folder' => 'storage', ## default folder name in public folder 'default_logo_text' => 'logo', ## default logo text 'logo_text_color' => '#000000', 'avatar_text_color' => '#f1c40f', 'avatar_background_color' => '#ffffff', 'default_svg_path' => 'users', ## folder name will be created in public/{folder}/users 'hash_svg_name' => true ## if you want to hash svg name by default true ];
you can change all configuration options as you want.
License
This package is open-source software licensed under the MIT license (MIT). Please see License File for more information.
Contact
If you have any questions or feedback, feel free to contact me via e-mail at abdallakaramdev@gmail.com
abdullah-karam/laravel-svg 适用场景与选型建议
abdullah-karam/laravel-svg 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 66 次下载、GitHub Stars 达 4, 最近一次更新时间为 2023 年 07 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 abdullah-karam/laravel-svg 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 abdullah-karam/laravel-svg 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 66
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-07-12