tomatstudio/yii2-photosyn

Yii2 client for working with Photosyn service

Installs: 11

Dependents: 0

Suggesters: 0

Security: 0

Type:yii2-extension

dev-default 2017-11-06 13:57 UTC

This package is auto-updated.

Last update: 2020-08-10 11:06:56 UTC


README

This extension help to work with Photosyn service.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist tomatstudio/yii2-photosyn "*"

or add

"tomatstudio/yii2-photosyn": "*"

to the require section of your composer.json.

Usage

Configure component like that:

'components' => [
    'photosyn' => [
        'class' => 'tomatstudio\photosyn\PhotosynComponent',
        'apiClient' => 'your_api_client',
        'apiKey' => 'your_api_key',
    ],
    // ...
 ]

Upload image:

$uploadedImage = UploadedFile::getInstance($model, 'imageFile'))
$uploadedImagePath = Yii::getAlias('@webroot/uploads/tmp/') . time() . '.' . $uploadedImage->extension;
$uploadedImage->saveAs($uploadedImagePath);

$photosynImage = Yii::$app->photosyn->uploadImage($uploadedImagePath);

if ($photosynImage->result == 'success') {
    $model->filename = $photosynImage->filename;
    $model->hash = $photosynImage->hash;
    $model->mimetype = $photosynImage->mimetype;
    $model->size = (string)$photosynImage->size;
}

if ($model->save()) {
    unlink($uploadedImagePath);

}

Get image:

Yii::$app->photosyn->getUrl('46cd340a-35e1-4deb-bf6e-24c12bd12070'); // Full size
Yii::$app->photosyn->setWidth('300')->setHeight('100')->getUrl('46cd340a-35e1-4deb-bf6e-24c12bd12070'); // 300x100 size

Delete image:

Yii::$app->photosyn->deleteImage('46cd340a-35e1-4deb-bf6e-24c12bd12070');