PHP code example of arrratars / laravel

1. Go to this page and download the library: Download arrratars/laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

arrratars / laravel example snippets


use Arrratars\Laravel\Facades\Arrratars;

// Get SVG string
$svg = Arrratars::svg('[email protected]');

// That's it. $svg is a complete <svg>...</svg> string.

// routes/api.php
Route::get('/avatar/{value}', function (string $value) {
    return response(Arrratars::svg($value, ['style' => 'shape', 'size' => 128]))
        ->header('Content-Type', 'image/svg+xml')
        ->header('Cache-Control', 'public, max-age=31536000');
});

use Illuminate\Support\Facades\Storage;
use Arrratars\Laravel\Facades\Arrratars;

Storage::disk('s3')->put(
    'avatars/user123.svg',
    Arrratars::svg('[email protected]', ['size' => 256, 'style' => 'shape'])
);

Arrratars::saveTo('[email protected]', storage_path('app/avatars/user.svg'));

// PNG (rmat' => 'png',
    'size' => 256,
]);

$user->avatar_svg = Arrratars::svg($user->email, ['style' => 'shape', 'size' => 128]);
$user->save();

$src = Arrratars::toBase64('[email protected]', ['size' => 64]);
// → data:image/svg+xml;base64,PHN2ZyB4bWxu...

$svg = arrratars('anything');              // returns SVG string
$base64 = arrratars_base64('anything');    // returns data:image/svg+xml;base64,...

// app/Http/Controllers/UserController.php
public function show(User $user)
{
    return response()->json([
        'name' => $user->name,
        'avatar_svg' => Arrratars::svg($user->email, ['style' => 'shape']),
        'avatar_url' => url('/api/avatar/' . $user->email),
    ]);
}
bash
php artisan vendor:publish --tag=arrratars-config
blade
<x-arrratars value="[email protected]" />

<x-arrratars value="[email protected]" style="shape" :size="64" :shadow="true" :border="true" />