1. Go to this page and download the library: Download maxxxam/phumbor-yii library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
maxxxam / phumbor-yii example snippets
foreach ($_FILES as &$file){
$urlUpload = Yii::$app->thumbor->upload($file);
}
class Image extends File implements ImageInterface
{
public function getSrc():string
{
return Yii::$app->thumbor->getFullUrl($this->id_external);
}
public function getMeta($src = null): array
{
$source = $src ?: Yii::$app->thumbor->getUrlBuilder($this->getSrc(), true)->metadataOnly(true)->__toString();
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $source);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$result = json_decode(curl_exec($curl), true);
curl_close($curl);
return $result['thumbor'] ?? null;
}
public function getVariants(){
return new ImageVariants($this);
}
}
interface ImageInterface
{
public function getSrc():string;
public function getMeta($src = null):array;
}
abstract class AbstractImageSize extends MagicMethods implements ImageInterface
{
private $_image;
public function __construct(ImageInterface $image)
{
$this->_image = $image;
}
private function getUrlBuilder($source, $uploadServer = false): Builder{
return \Yii::$app->thumbor->getUrlBuilder($source, $uploadServer);
}
public function getSrc():string
{
$builder = $this->getUrlBuilder($this->_image->getSrc());
return $this->applyActions($builder)->__toString();
}
public function getMeta($src = null):array
{
$builder = $this->getUrlBuilder($this->_image->getSrc(), true);
$path = $this->applyActions($builder)->metadataOnly(true)->__toString();
return $this->_image->getMeta($path);
}
/**
* Apply filters
* @param Builder $builder
* @return mixed
*/
abstract protected function applyActions($builder);
}
class ImageSmall extends AbstractImageSize
{
/**
* @inheritdoc
*/
protected function applyActions($builder){
return $builder->resize(100, 100);
}
}
class ImageVariants extends MagicMethods
{
private $_image;
public function __construct(ImageInterface $image)
{
$this->_image = $image;
}
public function getSmall():ImageSmall{
return new ImageSmall($this->_image);
}
...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.