Skip to content

Commit 80aa5f6

Browse files
committed
feat(fa-v5): added v2 support for pins
1 parent 1f01846 commit 80aa5f6

7 files changed

Lines changed: 897 additions & 976 deletions

File tree

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

‎app/Http/Controllers/API/v1/FontAwesome/v5/PinController.php‎

Lines changed: 4 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -2,100 +2,15 @@
22

33
namespace App\Http\Controllers\API\v1\FontAwesome\v5;
44

5-
use App\Helpers\Encoders\FontAwesome\v5\FontAwesomeV5Encoder;
5+
use App\Actions\FontAwesome\v5\CreatePin;
66
use App\Http\Controllers\Controller;
7-
use Illuminate\Support\Facades\Request;
8-
use Intervention\Image\Facades\Image as Image;
7+
use Illuminate\Http\Request;
98

109
class PinController extends Controller
1110
{
12-
protected function getIconFontPath($icon)
11+
public function show(Request $request)
1312
{
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) + 3; //calibrated offset +3
43-
$hoffset = (Request::get('hoffset') ?: 0) + 1; // calibrated offset +1
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, $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) {
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 ($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 ($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-
}
13+
$img = CreatePin::run($request->all());
9914

10015
return $img->response('png');
10116
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\API\v2\FontAwesome\v5;
4+
5+
use App\Actions\FontAwesome\v5\CreatePin;
6+
use App\Actions\Image\ResizeToHeight;
7+
use App\Actions\Image\TrimTransparentBorder;
8+
use App\Http\Controllers\Controller;
9+
use Illuminate\Http\Request;
10+
11+
class PinController extends Controller
12+
{
13+
const SCALE = 2.0;
14+
15+
const FORCE_ODD_SIZE = true;
16+
17+
public function show(Request $request)
18+
{
19+
$size = $request->get('size') ?: 30;
20+
$img = CreatePin::run($request->all(), self::SCALE, self::FORCE_ODD_SIZE);
21+
TrimTransparentBorder::run($img);
22+
ResizeToHeight::run($img, $size);
23+
24+
return $img->response('png');
25+
}
26+
}

‎public/css/app.css‎

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,6 @@ input::-moz-placeholder, textarea::-moz-placeholder {
318318
color: #9ca3af; /* 2 */
319319
}
320320

321-
input:-ms-input-placeholder, textarea:-ms-input-placeholder {
322-
opacity: 1; /* 1 */
323-
color: #9ca3af; /* 2 */
324-
}
325-
326321
input::placeholder,
327322
textarea::placeholder {
328323
opacity: 1; /* 1 */
@@ -686,15 +681,6 @@ video {
686681
.p-2 {
687682
padding: 0.5rem;
688683
}
689-
.p-16 {
690-
padding: 4rem;
691-
}
692-
.p-10 {
693-
padding: 2.5rem;
694-
}
695-
.p-4 {
696-
padding: 1rem;
697-
}
698684
.px-2 {
699685
padding-left: 0.5rem;
700686
padding-right: 0.5rem;
@@ -703,9 +689,9 @@ video {
703689
padding-left: 1rem;
704690
padding-right: 1rem;
705691
}
706-
.py-1 {
707-
padding-top: 0.25rem;
708-
padding-bottom: 0.25rem;
692+
.py-0 {
693+
padding-top: 0px;
694+
padding-bottom: 0px;
709695
}
710696
.px-3 {
711697
padding-left: 0.75rem;
@@ -715,10 +701,6 @@ video {
715701
padding-top: 0.5rem;
716702
padding-bottom: 0.5rem;
717703
}
718-
.py-0 {
719-
padding-top: 0px;
720-
padding-bottom: 0px;
721-
}
722704
.pt-4 {
723705
padding-top: 1rem;
724706
}
@@ -920,11 +902,6 @@ video {
920902
padding: 2.5rem;
921903
}
922904

923-
.md\:py-10 {
924-
padding-top: 2.5rem;
925-
padding-bottom: 2.5rem;
926-
}
927-
928905
.md\:pb-10 {
929906
padding-bottom: 2.5rem;
930907
}

‎public/mix-manifest.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"/js/app.js": "/js/app.js",
33
"/css/app.css": "/css/app.css",
4-
"/images/hero-3d.jpg": "/images/hero-3d.jpg",
54
"/images/map.jpg": "/images/map.jpg"
65
}

‎routes/web.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
Route::group(['prefix' => 'font-awesome', 'namespace' => 'FontAwesome'], function () {
5858
// FONT-AWESOME 5
5959
Route::group(['prefix' => 'v5', 'namespace' => 'v5'], function () {
60+
Route::get('pin', 'PinController@show');
6061
Route::get('icon', 'IconController@show');
6162
Route::get('icon-stack', 'IconStackController@show');
6263
});

0 commit comments

Comments
 (0)