cable8mm / view-transformer
Generate deterministic default profile names and avatar URLs for users.
Requires
- php: ^8.0
Requires (Dev)
- laravel/pint: ^1.0
- phpunit/phpunit: ^9.0|^10.0|^11.0
README
A PHP library for generating pet (dog/cat) avatar images and nicknames. Provides consistent profile defaults based on user IDs.
Features
- 4,080 dog/cat nicknames (breed names + descriptive adjectives)
- 80 dog avatar images
- 41 cat avatar images
- 3 image sizes supported (large, medium, small)
- Laravel Blade support
- Deterministic algorithm (same ID always returns same result)
- Configurable avatar base URL in Laravel
Installation
composer require cable8mm/pretty-profile
Laravel configuration
The default avatar base URL is https://cabinet-pets.palgle.com/avatars. To use
another host or path, set the following environment variable:
PRETTY_PROFILE_AVATAR_BASE_URL=https://cdn.example.com/avatars
The configuration can also be published with:
php artisan vendor:publish --tag=pretty-profile-config
Quick Start
use Cable8mm\PrettyProfile\PrettyProfile; // Generate nickname $nickname = PrettyProfile::getInstance()->nickname(12345); // Output: "Happy Poodle" (example) // Get dog image URL $dogImage = PrettyProfile::getInstance()->dog(12345); // Output: "https://cabinet-pets.palgle.com/avatars/dog/61.png" // Get cat image URL (medium size) $catImage = PrettyProfile::getInstance()->cat(12345, 'medium'); // Output: "https://cabinet-pets.palgle.com/avatars/cat/medium/13.png"
API Reference
PrettyProfile
Generates nicknames and pet image URLs based on user ID.
Methods
nickname(int $id): string
Generates a nickname from user ID.
Parameters:
$id(int): User ID (must be >= 1)
Returns: Adjective + breed name combination (e.g., "Ordinary Nebelung")
Throws: InvalidArgumentException - If ID is 0 or negative
Example:
echo PrettyProfile::getInstance()->nickname(1); //=> Ordinary Nebelung echo PrettyProfile::getInstance()->nickname(2); //=> Sexy Norwegian Forest
cat(int $id, ?string $size = null): string
Returns a cat image URL.
Parameters:
$id(int): User ID (must be >= 1)$size(string|null): 'large', 'medium', 'small', or null (original size)
Returns: Image URL
Throws: InvalidArgumentException - If ID is invalid or size is not valid
Example:
echo PrettyProfile::getInstance()->cat(1); //=> https://cabinet-pets.palgle.com/avatars/cat/1.png echo PrettyProfile::getInstance()->cat(1, 'medium'); //=> https://cabinet-pets.palgle.com/avatars/cat/medium/1.png
dog(int $id, ?string $size = null): string
Returns a dog image URL.
Parameters:
$id(int): User ID (must be >= 1)$size(string|null): 'large', 'medium', 'small', or null (original size)
Returns: Image URL
Throws: InvalidArgumentException - If ID is invalid or size is not valid
Example:
echo PrettyProfile::getInstance()->dog(1); //=> https://cabinet-pets.palgle.com/avatars/dog/1.png echo PrettyProfile::getInstance()->dog(1, 'large'); //=> https://cabinet-pets.palgle.com/avatars/dog/large/1.png
cats(?string $size = null): array
Returns array of all cat image URLs.
Parameters:
$size(string|null): 'large', 'medium', 'small', or null (original size)
Returns: Array of image URLs (41 items)
Example:
$cats = PrettyProfile::getInstance()->cats(); // Array of 41 image URLs $cats = PrettyProfile::getInstance()->cats('medium'); // Array of 41 medium-sized image URLs
dogs(?string $size = null): array
Returns array of all dog image URLs.
Parameters:
$size(string|null): 'large', 'medium', 'small', or null (original size)
Returns: Array of image URLs (80 items)
Example:
$dogs = PrettyProfile::getInstance()->dogs(); // Array of 80 image URLs $dogs = PrettyProfile::getInstance()->dogs('small'); // Array of 80 small-sized image URLs
profileImage(int $id, ?string $image = null, string $animal = 'dog'): string
Helper method for Laravel Blade templates.
Parameters:
$id(int): User ID$image(string|null): Custom image URL (used if provided)$animal(string): 'dog' or 'cat' (default: 'dog')
Returns: Image URL
Throws: InvalidArgumentException - If animal is not 'dog' or 'cat'
Example:
{{ PrettyProfile::profileImage(4123, animal: 'dog') }} {{-- Output: https://cabinet-pets.palgle.com/avatars/dog/43.png --}} {{ PrettyProfile::profileImage(4123, animal: 'cat') }} {{-- Output: https://cabinet-pets.palgle.com/avatars/cat/10.png --}} {{ PrettyProfile::profileImage(4123, image: 'https://example.com/custom.png') }} {{-- Output: https://example.com/custom.png --}}
backgroundImage(?string $background_image = null): string
Returns a background image URL.
Parameters:
$background_image(string|null): Custom background image URL
Returns: Background image URL
Example:
echo PrettyProfile::backgroundImage(); //=> https://cabinet-pets.palgle.com/bg/bg-1.png echo PrettyProfile::backgroundImage('https://example.com/bg.png'); //=> https://example.com/bg.png
Usage Examples
Generate User Profile Images
use Cable8mm\PrettyProfile\PrettyProfile; $userId = 393939; // Generate nickname $nickname = PrettyProfile::getInstance()->nickname($userId); echo $nickname; // "Ordinary Nebelung" // Get dog profile image $dogImage = PrettyProfile::getInstance()->dog($userId); echo $dogImage; // "https://cabinet-pets.palgle.com/avatars/dog/64.png" // Get cat profile image (medium size) $catImage = PrettyProfile::getInstance()->cat($userId, 'medium'); echo $catImage; // "https://cabinet-pets.palgle.com/avatars/cat/medium/10.png"
Get All Images
use Cable8mm\PrettyProfile\PrettyProfile; // Get all dog images (original size) $allDogs = PrettyProfile::getInstance()->dogs(); // Get all cat images (medium size) $allCatsMedium = PrettyProfile::getInstance()->cats('medium'); // Generate preview foreach ($allDogs as $index => $url) { echo "\n"; }
Laravel Blade Integration
{{-- Basic usage --}} <img src="{{ PrettyProfile::profileImage($user->id, animal: 'dog') }}" alt="Profile"> {{-- Cat image --}} <img src="{{ PrettyProfile::profileImage($user->id, animal: 'cat') }}" alt="Profile"> {{-- Custom image (takes priority) --}} <img src="{{ PrettyProfile::profileImage($user->id, image: $user->custom_avatar) }}" alt="Profile">
Exception Handling
use Cable8mm\PrettyProfile\PrettyProfile; try { // Invalid ID (0 or negative) PrettyProfile::getInstance()->cat(0); } catch (\InvalidArgumentException $e) { echo $e->getMessage(); // "The value must be over 0, so a value of 0 is not valid." } try { // Invalid size PrettyProfile::getInstance()->dog(1, 'huge'); } catch (\InvalidArgumentException $e) { echo $e->getMessage(); // "The value must be "large" or "medium" or "small", so a value of "huge" is not valid." } try { // Invalid animal PrettyProfile::profileImage(1, animal: 'rabbit'); } catch (\InvalidArgumentException $e) { echo $e->getMessage(); // "The value must be dog or cat. rabbit is not valid." }
Algorithm
Image Selection Algorithm
Uses the remainder of dividing user ID by the number of images. This ensures:
- Deterministic: Same ID always returns the same image
- Uniform distribution: If IDs are evenly distributed, images are evenly distributed
- Unlimited: Works correctly even if ID exceeds image count
// Example: Dog images (80 total) $id = 827342; $imageNumber = ($id - 1) % 80 + 1; // 62 // User #827342 always uses image #62
Nickname Generation Algorithm
Selects prefix (adjective) and suffix (breed name) independently using modular arithmetic.
// Example: ID 1 $prefixIndex = (1 - 1) % 40; // 0 → First adjective $nicknameIndex = (1 - 1) % 66; // 0 → First breed name // Result: "Ordinary Nebelung" (example)
Preview
Dog artworks
Cat artworks
Formatting
composer lint # Modify all files to comply with the PSR-12. composer inspect # Inspect all files to ensure compliance with PSR-12.
Test
composer test
License
The View Transformer project is open-sourced software licensed under the MIT license.
Artworks © 2020 by Samgu Lee is licensed under CC BY-NC-ND 4.0. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/4.0/