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