Help libraries for PHP development
PHP Helper has the following requirements:
- PHP 7.0+ Image manipulation The Imagine Helper has the following requirements:
- Imagine 1.0.1+
- GD
composer require codepso/php-helper
- $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
- 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 |
- $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
- filename:
- $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();
}
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
The Aimeos TYPO3 extension is licensed under the terms of the GPL Open Source license and is available for free.