codepso/php-helper

Help libraries for PHP development

v1.1.0 2018-11-05 00:32 UTC

This package is not auto-updated.

Last update: 2024-04-19 05:21:09 UTC


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 | required Name of the image
  • $params: array | required
    • path: string | required Path of the image
    • filter: string | required Resize info ex: 300x200, 100x100
    • ratio: int | optional Inset:1 (default), Outbound: 2
    • rename: string | optional New name of the image
<?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
or in ou

saveBase64($params, $path)

  • $params: array | required
    • filename: string | required Name of the image
    • value: string | required Image in base64 format
    • rename: string | optional New name of the image
  • $path: string | required The 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