|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Http\Controllers\API\v1; |
| 4 | + |
| 5 | +use App\Http\Controllers\Controller as Controller; |
| 6 | +use App\Helpers\FontAwesomeEncoder; |
| 7 | +use Illuminate\Support\Facades\Request; |
| 8 | +use Intervention\Image\Facades\Image as Image; |
| 9 | + |
| 10 | +class FaStackController extends Controller |
| 11 | +{ |
| 12 | + protected function getDefaultOnIcon() |
| 13 | + { |
| 14 | + return 'fa-circle-o'; |
| 15 | + } |
| 16 | + |
| 17 | + protected function getIconFontPath($icon) |
| 18 | + { |
| 19 | + return base_path('resources/fonts/legacy/fontawesome-webfont.ttf'); |
| 20 | + } |
| 21 | + |
| 22 | + protected function getTextFontPath() |
| 23 | + { |
| 24 | + return base_path('resources/fonts/legacy/monofonto.ttf'); |
| 25 | + } |
| 26 | + |
| 27 | + protected function getUnicodeCharFromIcon($icon) |
| 28 | + { |
| 29 | + return FontAwesomeEncoder::getUnicodeFromIcon($icon); |
| 30 | + } |
| 31 | + |
| 32 | + public function show() |
| 33 | + { |
| 34 | + |
| 35 | + // OPEN ICON DEFAULT IMAGE |
| 36 | + $img = file_get_contents(resource_path('images/icon.png')); |
| 37 | + $img = Image::make($img); |
| 38 | + |
| 39 | + // INPUTS |
| 40 | + $icon = Request::get('icon') ?: null; |
| 41 | + $on = Request::get('on') ?: $this->getDefaultOnIcon(); |
| 42 | + |
| 43 | + // RESIZE THE ICON |
| 44 | + $size = Request::get('size') ?: 30; |
| 45 | + $iconSize = Request::get('iconsize') ?: ($size * 0.3); |
| 46 | + $voffset = Request::get('voffset') ?: 0; |
| 47 | + $hoffset = Request::get('hoffset') ?: 0; |
| 48 | + |
| 49 | + $img->resize($size, $size, function ($constraint) { |
| 50 | + $constraint->aspectRatio(); |
| 51 | + }); |
| 52 | + |
| 53 | + $large_color = (Request::get('oncolor') ?: Request::get('color')) ?: '000000'; |
| 54 | + $img->text($this->getUnicodeCharFromIcon($on), $size / 2, $size / 2, function ($font) use ($on, $img, $size, $large_color) { |
| 55 | + $font->file($this->getIconFontPath($on)); |
| 56 | + $font->size($size * 0.8); |
| 57 | + $font->color($large_color); |
| 58 | + $font->align('center'); |
| 59 | + $font->valign('center'); |
| 60 | + }); |
| 61 | + |
| 62 | + $small_color = Request::get('color') ?: null; |
| 63 | + $img->text($this->getUnicodeCharFromIcon($icon), ($size / 2) + $hoffset, ($size / 2) + $voffset, function ($font) use ($icon, $img, $size, $iconSize, $large_color, $small_color) { |
| 64 | + $font->file($this->getIconFontPath($icon)); |
| 65 | + $font->size($iconSize); |
| 66 | + $font->color($small_color ?: $large_color); |
| 67 | + $font->align('center'); |
| 68 | + $font->valign('center'); |
| 69 | + }); |
| 70 | + |
| 71 | + $label = Request::get('label') ?: null; |
| 72 | + $labelOffset = Request::get('labelOffset') ?: 0; |
| 73 | + if (!is_null($label)) { |
| 74 | + |
| 75 | + // ADD THE LABEL |
| 76 | + $img->text($this->getUnicodeCharFromIcon('fa-circle'), $size * 0.8, $size * 0.8, function ($font) use ($img, $size) { |
| 77 | + $font->file($this->getIconFontPath('fa-circle')); |
| 78 | + $font->size($size * 0.44); |
| 79 | + $font->color(Request::get('labelColor') ?: 'D9534F'); |
| 80 | + $font->align('center'); |
| 81 | + $font->valign('center'); |
| 82 | + }); |
| 83 | + |
| 84 | + // ADD THE LABEL TEXT |
| 85 | + $img->text($label, $size * 0.8 + $labelOffset, $size * 0.8, function ($font) use ($img, $size) { |
| 86 | + $font->file($this->getTextFontPath()); |
| 87 | + $font->size($size * 0.25); |
| 88 | + $font->color(Request::get('labelTextColor') ?: 'FFFFFF'); |
| 89 | + $font->align('center'); |
| 90 | + $font->valign('center'); |
| 91 | + }); |
| 92 | + } |
| 93 | + |
| 94 | + return $img->response('png'); |
| 95 | + } |
| 96 | +} |
0 commit comments