ImgSemCache
extends Controller
in package
Table of Contents
- $base_dir : string
- $browser : mixed
- $csrf_token : mixed
- $institucional : string|null
- $override_defined_constant : mixed
- $router : Router
- $sistema : Sistema
- $view : Engine
- $dirbase : array<string|int, mixed>
- $driver : string
- $file : string
- $filename : string
- $fontSize : int
- $h : int
- $Image : ImageManager
- $params : array<string|int, mixed>
- $source : string
- $w : int
- __construct() : mixed
- barcode() : void
- error() : void
- fit() : void
- index() : void
- resize() : void
- formatToSelect() : array<string|int, mixed>|null
- getSource() : string
- listFilesAndFolders() : array<string|int, mixed>|null
- render() : void
- toCamelCase() : string
- create() : void
- fontDirbase() : mixed
- private function response(array $data, array $crop = null): void { $file = $this->structure($data); if ($file) { $defs = $this->getDefs(); $defs['fm'] = "webp"; if (!is_null($crop)) { $defs = array_merge($defs, $crop); } $this->server->outputImage($file, $defs); } else { $this->create($data['param4'], $this->getDefs()['w'], $this->getDefs()['h'] ?? null); } } private function structure(array $data): ?string { parse_str(base64_decode(filter_var($data['param3'], FILTER_SANITIZE_STRIPPED)), $defs);
- instanceOrRedirect() : void
- make() : Image|null
- path() : string
- renderImage() : void
- show() : void
Properties
$base_dir
protected
string
$base_dir
$browser
protected
mixed
$browser
$csrf_token
protected
mixed
$csrf_token
$institucional
protected
string|null
$institucional
$override_defined_constant
protected
mixed
$override_defined_constant
$router
protected
Router
$router
$sistema
protected
Sistema
$sistema
$view
protected
Engine
$view
$dirbase
private
array<string|int, mixed>
$dirbase
$driver
private
string
$driver
$file
private
string
$file
$filename
private
string
$filename
$fontSize
private
int
$fontSize
$h
private
int
$h
$Image
private
ImageManager
$Image
$params
private
array<string|int, mixed>
$params
$source
private
string
$source
= "\Source\Controllers\"
$w
private
int
$w
Methods
__construct()
public
__construct(Router $router) : mixed
Parameters
- $router : Router
Return values
mixed —barcode()
public
barcode(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
Return values
void —error()
public
error(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
Return values
void —fit()
public
fit(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
Return values
void —index()
public
index(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
Return values
void —resize()
public
resize(array<string|int, mixed> $data) : void
Parameters
- $data : array<string|int, mixed>
Return values
void —formatToSelect()
protected
formatToSelect(string $field, string $value[, array<string|int, mixed> $array = null ]) : array<string|int, mixed>|null
Parameters
- $field : string
- $value : string
- $array : array<string|int, mixed> = null
Return values
array<string|int, mixed>|null —getSource()
protected
getSource() : string
Return values
string —listFilesAndFolders()
protected
listFilesAndFolders(string $path[, bool $basename = false ]) : array<string|int, mixed>|null
Parameters
- $path : string
- $basename : bool = false
Return values
array<string|int, mixed>|null —render()
protected
render(string $template_name[, array<string|int, mixed> $data = [] ][, string $title = null ][, string $desciption = null ][, string $url = null ][, string $image = null ]) : void
Parameters
- $template_name : string
- $data : array<string|int, mixed> = []
- $title : string = null
- $desciption : string = null
- $url : string = null
- $image : string = null
Return values
void —toCamelCase()
protected
toCamelCase(string $string) : string
Parameters
- $string : string
Return values
string —create()
private
create() : void
Return values
void —fontDirbase()
private function response(array $data, array $crop = null): void { $file = $this->structure($data); if ($file) { $defs = $this->getDefs(); $defs['fm'] = "webp"; if (!is_null($crop)) { $defs = array_merge($defs, $crop); } $this->server->outputImage($file, $defs); } else { $this->create($data['param4'], $this->getDefs()['w'], $this->getDefs()['h'] ?? null); } } private function structure(array $data): ?string { parse_str(base64_decode(filter_var($data['param3'], FILTER_SANITIZE_STRIPPED)), $defs);
private
fontDirbase() : mixed
$source = $this->dirbase . DIRECTORY_SEPARATOR . $defs['folder'];
$this->server = ServerFactory::create([ 'source' => $source, 'cache' => $this->dirbase . DIRECTORY_SEPARATOR . "cache", 'driver' => 'gd', ]);
unset($defs['folder']); $this->setDefs($defs);
$file = filter_var($data['param4'], FILTER_SANITIZE_STRIPPED);
if (!file_exists($source . DIRECTORY_SEPARATOR . $file)) { return null; }
return $file; }
private function getDefs() { return $this->defs; }
private function setDefs($defs): void { $this->defs = $defs; } private function create(string $text, int $w, int $h = null): void { if (is_null($h)) { $h = $w; } header('Content-Type: image/png'); $font = $this->fontDirbase(); if ($w === $h) { $size = intval(100 * ($w / $h) / 10); } elseif ($w < $h) { $size = intval(100 * ($w / $h));//falta calcular } elseif ($w > $h) { $size = intval(100 / ($w / $h));//falta calcular } $bbox = imagettfbbox($size, 0, $font, $text); $width = abs($bbox[2] - $bbox[0]); $height = abs($bbox[7] - $bbox[1]); $x = $bbox[0] + ($width / 2) - ($bbox[4] / 2); $y = $bbox[1] + ($height / 2) - ($bbox[5] / 2);
$im = imagecreatetruecolor($w, $h); $white = imagecolorallocate($im, 255, 255, 255); $imgbg = imagecolorallocate($im, 255, 100, 100); imagefilledrectangle($im, 0, 0, 600, 400, $imgbg); imagettftext( $im, $size, 0, intval(($w / 2 - $width / 2) - $x), intval(($h / 2 - $height / 2) + $y), $white, $font, $text ); imagepng($im); imagedestroy($im); }
Return values
mixed —instanceOrRedirect()
private
instanceOrRedirect(string $controller, mixed $class, array<string|int, mixed> $data[, bool $db = false ]) : void
Parameters
- $controller : string
- $class : mixed
- $data : array<string|int, mixed>
- $db : bool = false
Return values
void —make()
private
make() : Image|null
Return values
Image|null —path()
private
path() : string
Return values
string —renderImage()
private
renderImage(Image $img) : void
Parameters
- $img : Image
Return values
void —show()
private
show() : void