Maginium
Docs
Docs
  • Welcome
  • Getting Started
    • Quickstart
    • Installation
    • Structure
  • The Basics
    • Concurrency
    • 🔤Strings
    • ⚙️Actions
    • 🗃️Cache
    • 🗂️Collections
    • 🔲Component
    • ⚙️Config
    • 💬Console
    • 🗃️Database
      • Overview
      • Eloquent
      • Seeder
      • Migration
      • Models
      • Factories
      • Schemas
      • Traits
      • Concerns
    • 🛅Container
    • 🔠Enum
    • 📦Event
    • 📝Log
    • 🔢Pagination
    • 💬Prompts
    • 🌐Request
    • 📡Response
    • ⚡Redis
    • 📏Resize
    • 🔌Serializer
      • Json
      • Serializer
      • Closure Serializer
    • 🔑Uuid
    • 👤Avatar
    • 🔐Hashing
    • 📤Dto
      • Overview
      • Attributes
    • 🌍Locale
    • 🔗Token
      • Api Keys
      • Admin Token
      • Customer Token
    • 🕘Message Queue
    • 🖼️Media
    • Helpers
    • 📜Crud
      • Filters and Sorts
        • introduction
        • Basic Usage
        • JS Examples
          • Available Methods
          • Sorts
          • Filters
        • Rename Fields
        • Relation Fields
        • Changing Params Source
        • Allowed Fields
        • Queries and javascript examples
        • Sort null values last
        • Restrict
        • Custom Filters
  • Commerce Modules
    • API Key Module
    • Auth Module
    • Cart Module
    • Customer Module
    • Inventory Module
    • Fulfillment Module
    • Order Module
    • Payment Module
    • Pricing Module
    • Product Module
    • Promotion Module
    • User Module
  • SDKs and Tools
    • create-maginium-app
    • Maginium CLI
    • JS SDK
    • Storefront Starter
Powered by GitBook
On this page
  • Introduction
  • Usage
  1. The Basics

Avatar

PreviousUuidNextHashing

Last updated 4 months ago

Display a unique avatar for any user based on their (initials) name.

This Module is inspired by [Laravolt](https://github.com/laravolt/avatar)

// This will output data-uri (base64 image data), e.g., data:image/png;base64,iVBORw0KGg...
Avatar::create('Joko Widodo')->toBase64();

// Use in view to display initials as an image
<img src="{{ Avatar::create('Joko Widodo')->toBase64() }}" />

Avatar::create('Susilo Bambang Yudhoyono')->save('sample.png');
Avatar::create('Susilo Bambang Yudhoyono')->save('sample.jpg', 100); // Quality = 100

Avatar::create('uyab@example.net')->toGravatar();
// Output: http://gravatar.com/avatar/...

Avatar::create('uyab@example.net')->toGravatar(['d' => 'identicon', 'r' => 'pg', 's' => 100]);
// Output: http://gravatar.com/avatar/...&d=identicon&r=pg&s=100

Gravatar parameter reference

Avatar::create('Susilo Bambang Yudhoyono')->toSvg();

You may specify a custom font family for your SVG text.

<head>
    <!-- Using Google Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Inter" rel="stylesheet">

    <!-- OR Setup custom style -->
    <style>
    @font-face {
        font-family: Inter;
        src: url({{ asset('fonts/inter.woff') }});
    }
    </style>
</head>
Avatar::create('Susilo Bambang Yudhoyono')->setFontFamily('Inter')->toSvg();
Avatar::create('Abdul Somad')->getImageObject();

Returns an instance of the Intervention image object, enabling further processing.

The library tries to render initials as supplied. For non-ASCII characters (e.g., ā, Ě), their visibility depends on font support. Alternatively, non-ASCII characters can be converted to their closest ASCII counterparts using Stringy.

Avatar::create('Soekarno')->setDimension(100); // Width = Height = 100 pixels
Avatar::create('Soekarno')->setDimension(100, 200); // Width = 100, Height = 200
Avatar::create('Soekarno')->setBackground('#001122');
Avatar::create('Soekarno')->setForeground('#999999');
Avatar::create('Soekarno')->setFontSize(72);
Avatar::create('Soekarno')->setFont('/path/to/font.ttf');
Avatar::create('Soekarno')->setBorder(1, '#aabbcc'); // Size = 1, Color = #aabbcc
Avatar::create('Soekarno')->setBorder(1, '#aabbcc', 10); // Border radius = 10 (for SVG only)
Avatar::create('Soekarno')->setShape('square');

// Since v3.0.0
Avatar::create('Soekarno')->setTheme('colorful'); // Set exact theme
Avatar::create('Soekarno')->setTheme(['grayscale-light', 'grayscale-dark']); // Random theme from options

// Chaining
Avatar::create('Habibie')->setDimension(50)->setFontSize(18)->toBase64();

👤
Introduction
Usage
Introduction
Usage
Output as Base64
Save as File
Output as Gravatar
Output as SVG
Get Underlying Intervention Image Object
Non-ASCII Character
Overriding Config at Runtime