codepso/php-helper
Composer 安装命令:
composer require codepso/php-helper
包简介
Help libraries for PHP development
README 文档
README
php-helper
Help libraries for PHP development
Table of content
Requirements
PHP Helper has the following requirements:
- PHP 7.0+ Image manipulation The Imagine Helper has the following requirements:
- Imagine 1.0.1+
- GD
Installation
composer require codepso/php-helper
MainHelper
isValid($params, $rules)
populate($object, $data, $ignore)
getIgnoredAttributes($object, $attr)
getClass($object, $namespace)
getElapsed($date)
generatePassword($length)
isJSON($string)
ImageHelper
createThumbnail($filename, $params)
- $filename:
string | requiredName of the image - $params:
array | required- path:
string | requiredPath of the image - filter:
string | requiredResize info ex: 300x200, 100x100 - ratio:
int | optionalInset:1 (default), Outbound: 2 - rename:
string | optionalNew name of the image
- path:
<?php require_once 'vendor/autoload.php'; use Codepso\PHPHelper\ImageHelper; try { // ratio: 1 (inset) $p = ['path' => 'assets/files', 'filter' => '200x200']; $r1 = ImageHelper::createThumbnail('teddy.png', $p); if (!$r1->status) { throw new \Exception($r1->message); } // ratio: 2 (outbound) $p = ['path' => 'assets/files', 'filter' => '200x200', 'rename' => 'teddy-2.png', 'ratio' => 2]; $r2 = ImageHelper::createThumbnail('teddy.png', $p); if (!$r2->status) { throw new \Exception($r2->message); } } catch (\Exception $e) { $e->getMessage(); }
| Original | Inset (200x200) | Outbound (200x200) |
|---|---|---|
| 366x232px | 200x127px | 200x200px |
saveBase64($params, $path)
- $params:
array | required- filename:
string | requiredName of the image - value:
string | requiredImage in base64 format - rename:
string | optionalNew name of the image
- filename:
- $path:
string | requiredThe path to save the file
<?php require_once 'vendor/autoload.php'; use Codepso\PHPHelper\ImageHelper; try { $p = [ 'filename' => 'box.png', 'value' => 'iVBORw0KGgoAAAANSUhEUgAAABoAAAAYAQMAAADeTH+GAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAA1BMVEWIkr9Q9TFnAAAAC0lEQVQIHWMYIAAAAHgAASxSckIAAAAASUVORK5CYII=' ]; $r = ImageHelper::saveBase64($p, 'assets/files'); if (!$r->status) { throw new \Exception($r->message); } } catch (\Exception $e) { $e->getMessage(); }
JWTHelper
encode($data, $scope)
encode($jwt, $scope)
Test
We are using Codeception
php vendor/bin/codecept run unit ImageHelperTest php vendor/bin/codecept run unit php vendor/bin/codecept run ImageHelperTest:testSaveBase64 php vendor/bin/codecept run ImageHelperTest:testSaveBase64WithNewName
License
The Aimeos TYPO3 extension is licensed under the terms of the GPL Open Source license and is available for free.
Links
统计信息
- 总下载量: 45
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-02-26