Created
October 13, 2016 18:20
-
-
Save mariano-aguero/543a37e3ef52b55404c14abfd2a597fd to your computer and use it in GitHub Desktop.
Cloudinary - Lumen - Helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\V1\Helpers; | |
use Cloudinary; | |
use Cloudinary\Uploader; | |
/* @see http://cloudinary.com/documentation/php_image_upload#text_creation **/ | |
/** | |
* Class CloudinaryHelper | |
* @package App\V1\Helpers | |
*/ | |
class CloudinaryHelper | |
{ | |
/** | |
* Cloudinary Cloudinary | |
* | |
* @var Cloudinary | |
*/ | |
protected $cloudinary; | |
/** | |
* Cloudinary Uploader. | |
* | |
* @var \Cloudinary\Uploader | |
*/ | |
protected $uploader; | |
/** | |
* CloudinaryHelper constructor. | |
* @param $appName | |
* @param $key | |
* @param $secret | |
*/ | |
public function __construct() | |
{ | |
$this->cloudinary = new Cloudinary; | |
$this->uploader = new Uploader; | |
$this->cloudinary->config(array( | |
"cloud_name" => env('CLOUDINARY_NAME'), | |
"api_key" => env('CLOUDINARY_API_KEY'), | |
"api_secret" => env('CLOUDINARY_API_SECRET'), | |
)); | |
} | |
/** | |
* Cloudinary instance. | |
* | |
* @return \Cloudinary | |
*/ | |
public function getCloudinary() | |
{ | |
return $this->cloudinary; | |
} | |
/** | |
* Cloudinary uploader instance. | |
* | |
* @return \Cloudinary\Uploader | |
*/ | |
public function getUploader() | |
{ | |
return $this->uploader; | |
} | |
/** | |
* Upload image to cloudinary. | |
* | |
* @param mixed $source | |
* @param array $options | |
* @return array uploaded data | |
*/ | |
public function upload($source, $options = []) | |
{ | |
return $this->getUploader()->upload($source, $options); | |
} | |
/** | |
* Display image. | |
* | |
* @param string $publicId | |
* @param array $options | |
* @return string | |
*/ | |
public function show($publicId, $options = []) | |
{ | |
return $this->getCloudinary()->cloudinary_url($publicId, $options); | |
} | |
/** | |
* Create overlay. | |
* | |
* @param string $text | |
* @param array $options | |
* @return string | |
*/ | |
public function createOverlay($text, $options = []) | |
{ | |
return $this->getUploader()->text($text, $options); | |
} | |
/** | |
* @param $overlayId | |
* @param array $options | |
*/ | |
public function applyOverlay($overlayId, $options = []) | |
{ | |
return cl_image_tag($overlayId, $options); | |
} | |
/** | |
* Destroy image. | |
* | |
* @param string $publicId | |
* @param array $options | |
* @return array | |
*/ | |
public function destroy($publicId, $options = []) | |
{ | |
return $this->getUploader()->destroy($publicId, $options); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment