Skip to content

Commit 2fa4646

Browse files
committed
feat(fontawesome v5 pin controller): added pin controller
1 parent 12bf78b commit 2fa4646

File tree

16 files changed

+3354
-2
lines changed

16 files changed

+3354
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ yarn-error.log
1515
.vapor/
1616
.env.production
1717
.env.staging
18+
**.DS_Store

app/Helpers/Encoders/Encoder.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace App\Helpers\Encoders;
4+
5+
interface Encoder
6+
{
7+
/**
8+
* get unicode character from a font aweosome class.
9+
* @param string $icon the icon to fetch the unicode character for
10+
* @return string the unicode character or null
11+
*/
12+
public static function getUnicodeFromIcon($icon);
13+
14+
/**
15+
* get the file name containing the icon from unicode mapping.
16+
* @param string $icon the icon to fetch the unicode character for
17+
* @return string the webfont file location
18+
*/
19+
public static function getFile($icon);
20+
}

app/Helpers/Encoders/FontAwesome/v5/FontAwesomeV5Encoder.php

Lines changed: 3109 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
}

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"require": {
1111
"php": "^8.0.2",
1212
"guzzlehttp/guzzle": "^7.2",
13+
"intervention/image": "^2.7",
1314
"laravel/framework": "^9.11",
1415
"laravel/sanctum": "^2.14.1",
1516
"laravel/tinker": "^2.7",
@@ -65,4 +66,4 @@
6566
"minimum-stability": "dev",
6667
"prefer-stable": true,
6768
"version": "1.9.0"
68-
}
69+
}

composer.lock

Lines changed: 85 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
135 KB
Binary file not shown.

resources/fonts/legacy/monofonto.ttf

56.7 KB
Binary file not shown.

resources/fonts/monofonto.ttf

56.7 KB
Binary file not shown.

resources/images/icon.png

2.48 KB
Loading

resources/images/marker.png

3.93 KB
Loading

routes/web.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,38 @@
1616
Route::get('/', function () {
1717
return view('welcome');
1818
});
19+
20+
/*
21+
|--------------------------------------------------------------------------
22+
| Map Marker Routes
23+
|--------------------------------------------------------------------------
24+
|
25+
| Here is where you can register web routes for map markers
26+
|
27+
*/
28+
Route::group(['prefix' => 'api', 'namespace' => '\App\Http\Controllers\API', 'middleware' => 'api'], function () {
29+
Route::group(['prefix' => 'v1', 'namespace' => 'v1'], function () {
30+
31+
// LEGACY
32+
// Route::get('pin', 'PinController@show');
33+
// Route::get('fa', 'FaController@show');
34+
// Route::get('fa/stack', 'FaStackController@show');
35+
36+
// FONT-AWESOME
37+
Route::group(['prefix' => 'font-awesome', 'namespace' => 'FontAwesome'], function () {
38+
// FONT-AWESOME 4
39+
// Route::group(['prefix' => 'v4', 'namespace' => 'v4'], function () {
40+
// Route::get('pin', 'PinController@show');
41+
// Route::get('icon', 'IconController@show');
42+
// Route::get('icon-stack', 'IconStackController@show');
43+
// });
44+
45+
// FONT-AWESOME 5
46+
Route::group(['prefix' => 'v5', 'namespace' => 'v5'], function () {
47+
Route::get('pin', 'PinController@show');
48+
// Route::get('icon', 'IconController@show');
49+
// Route::get('icon-stack', 'IconStackController@show');
50+
});
51+
});
52+
});
53+
});

0 commit comments

Comments
 (0)