This document provides technical reference for the Renamer module in Lychee, which transforms filenames during import using customizable rules.
The Renamer module provides functionality to create, manage, and apply rules for renaming files during the import process. Users can define patterns and their replacements to transform filenames based on custom rules. This is particularly useful for standardizing filenames across a collection or replacing camera-generated prefixes with more meaningful names.
- Renamer Class: Located in
App\Metadata\Renamer, this is the main class that handles the application of renamer rules to strings. - RenamerRule Model: Represents a single renaming rule in the database.
- RenamerModeType Enum: Defines the available modes (FIRST, ALL, REGEX, TRIM, LOWER, UPPER, UCWORDS, UCFIRST).
- RenamerController: Handles API requests for managing renaming rules.
The Renamer module uses a renamer_rules table with the following structure:
| Column | Type | Description |
|---|---|---|
| id | bigint | Primary key |
| owner_id | bigint | Foreign key to the user who owns this rule |
| order | int | Processing order (lower numbers processed first) |
| rule | string | Name/identifier of the rule |
| description | string | Optional description of what the rule does |
| needle | string | The string to find (pattern to match) - ignored for case/trim modes |
| replacement | string | The replacement text - ignored for case/trim modes |
| mode | enum | Mode of operation (FIRST, ALL, REGEX, TRIM, LOWER, UPPER, UCWORDS, UCFIRST) |
| is_enabled | boolean | Whether the rule is active |
| is_photo_rule | boolean | Whether to apply rule to photo filenames |
| is_album_rule | boolean | Whether to apply rule to album titles |
The Renamer module supports eight modes of operation (defined in the RenamerModeType enum):
Replacement Modes (use needle/replacement fields):
- First occurrence (
FIRST): Replaces only the first occurrence of the pattern. - All occurrences (
ALL): Replaces all occurrences of the pattern. - Regular expression (
REGEX): Uses regular expressions for pattern matching and replacement.
Transformation Modes (ignore needle/replacement fields):
4. Trim (TRIM): Removes leading and trailing whitespace.
5. Lowercase (LOWER): Converts entire string to lowercase.
6. Uppercase (UPPER): Converts entire string to uppercase.
7. Uppercase words (UCWORDS): Capitalizes the first letter of each word.
8. Uppercase first (UCFIRST): Capitalizes only the first letter of the string.
Rules are processed in order from lowest to highest order value, meaning rules with lower order numbers have higher priority. Only enabled rules are applied.
The Renamer functionality can be controlled through several configuration settings:
renamer_enabled: Global switch to enable/disable renaming functionality.renamer_enforced: If enabled, only the system owner's rules are used, overriding user-specific rules.renamer_enforced_before: Apply system owner's rules before user-specific rules.renamer_enforced_after: Apply system owner's rules after user-specific rules.
- Import Process: The Renamer module is integrated with Lychee's import process to rename files upon upload or during server-side imports.
- Permission System: The renamer functionality checks if a user has supporter status through the
Verifyclass.
The Renamer module exposes API endpoints for managing rules and testing filename transformations. Refer to the api_v2.php routes file for the specific implementation details of these endpoints.
// Create a Renamer instance for a specific user
$renamer = new Renamer($user_id);
// Apply renamer rules to a single filename
$newFilename = $renamer->handle('IMG_1234.jpg');
// Apply renamer rules to multiple filenames
$newFilenames = $renamer->handleMany(['IMG_1234.jpg', 'DSC_5678.jpg']);$rule = new RenamerRule();
$rule->owner_id = Auth::id(); // Current user's ID
$rule->rule = 'Replace IMG_';
$rule->description = 'Replaces IMG_ with Photo_';
$rule->needle = 'IMG_';
$rule->replacement = 'Photo_';
$rule->mode = RenamerModeType::FIRST;
$rule->order = 1;
$rule->is_enabled = true;
$rule->is_photo_rule = true; // Apply to photo filenames
$rule->is_album_rule = false; // Don't apply to album titles
$rule->save();class RenamerRule extends Model
{
public int $id;
public int $owner_id; // User who owns this rule
public int $order; // Processing priority
public string $rule; // Rule name/identifier
public ?string $description; // Optional description
public string $needle; // Pattern to match (ignored for transformation modes)
public string $replacement; // Replacement text (ignored for transformation modes)
public RenamerModeType $mode; // FIRST, ALL, REGEX, TRIM, LOWER, UPPER, UCWORDS, or UCFIRST
public bool $is_enabled; // Active status
public bool $is_photo_rule; // Apply to photo filenames
public bool $is_album_rule; // Apply to album titles
}- Using Renamer - How-to guide for adding rules and applying patterns
- Backend Architecture - Overall backend structure
Last updated: January 21, 2026