Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Exiftool Laravel Package

phpexiftool/exiftool

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install Dependencies

    # Install PHP Exiftool package via Composer
    composer require alchemy-fr/exiftool
    
    # Install the required Perl ExifTool binary (Linux/macOS)
    sudo apt-get install libimage-exiftool-perl  # Debian/Ubuntu
    brew install exiftool                        # macOS (Homebrew)
    

    Windows users: Download from ExifTool's official site and add to PATH.

  2. Basic Usage

    use Alchemy\ExifTool\ExifTool;
    
    $exifTool = new ExifTool();
    $exifTool->setWorkingDirectory(__DIR__); // Optional: Set working dir for temp files
    
    // Read metadata from a single file
    $metadata = $exifTool->parseFile('path/to/image.jpg');
    dd($metadata); // Array of metadata (e.g., ['Image::Make' => 'Canon'])
    
    // Read metadata from multiple files
    $metadata = $exifTool->parseFiles(['file1.jpg', 'file2.png']);
    
  3. First Use Case: Batch Metadata Extraction

    $files = glob('uploads/*.{jpg,png}', GLOB_BRACE);
    $results = $exifTool->parseFiles($files);
    
    foreach ($results as $file => $data) {
        // Process each file's metadata (e.g., save to DB)
        DB::table('media_metadata')->updateOrCreate(
            ['path' => $file],
            ['make' => $data['Image::Make'] ?? null, 'model' => $data['Image::Model'] ?? null]
        );
    }
    

Implementation Patterns

Workflows

  1. Metadata Validation

    // Check if a file has GPS coordinates
    $metadata = $exifTool->parseFile('travel.jpg');
    if (isset($metadata['GPS::GPSLatitude'])) {
        // Process geotagged file
    }
    
  2. Editing Metadata

    // Update EXIF data (requires ExifTool binary with write permissions)
    $exifTool->writeFile(
        'output.jpg',
        [
            'Image::Make' => 'Modified',
            'XPComment' => 'Edited via PHP ExifTool'
        ],
        'input.jpg'
    );
    
  3. Recursive Directory Processing

    $iterator = new \RecursiveIteratorIterator(
        new \RecursiveDirectoryIterator('media/')
    );
    
    foreach ($iterator as $file) {
        if ($file->isFile()) {
            $metadata = $exifTool->parseFile($file->getPathname());
            // Log or index metadata
        }
    }
    

Integration Tips

  • Laravel Storage Integration

    use Illuminate\Support\Facades\Storage;
    
    $path = Storage::path('images/camera.jpg');
    $metadata = $exifTool->parseFile($path);
    
  • Queueing Heavy Operations

    // In a job class
    public function handle() {
        $files = File::where('processed', false)->get();
        foreach ($files as $file) {
            $metadata = $exifTool->parseFile(storage_path("app/{$file->path}"));
            // Save metadata to DB
        }
        File::whereIn('id', $files->pluck('id'))->update(['processed' => true]);
    }
    
  • Caching Results

    $cacheKey = 'metadata_' . md5($filePath);
    $metadata = Cache::remember($cacheKey, now()->addHours(1), function () use ($exifTool, $filePath) {
        return $exifTool->parseFile($filePath);
    });
    

Gotchas and Tips

Pitfalls

  1. Binary Path Issues

    • Symptom: ExifToolException: Could not execute ExifTool binary.
    • Fix: Explicitly set the binary path:
      $exifTool = new ExifTool('/usr/bin/exiftool');
      
    • Debug: Run which exiftool (Linux/macOS) or check PATH in Windows.
  2. Permission Denied

    • Symptom: ExifToolException: Permission denied.
    • Fix: Ensure the web server user (e.g., www-data, nginx) has read/write access to files and the ExifTool binary.
  3. Memory Limits

    • Symptom: Allowed memory size exhausted when parsing large batches.
    • Fix: Process files in chunks or increase memory_limit in php.ini.
  4. Corrupted Metadata

    • Symptom: Empty or malformed metadata for some files.
    • Fix: Use try-catch to handle exceptions:
      try {
          $metadata = $exifTool->parseFile($file);
      } catch (\Exception $e) {
          Log::warning("Failed to parse {$file}: " . $e->getMessage());
          $metadata = []; // Fallback
      }
      

Debugging

  • Enable Verbose Output
    $exifTool->setVerbose(true); // Logs raw ExifTool output to STDERR
    
  • Check ExifTool Version
    $version = $exifTool->getVersion();
    // Ensure it matches your PHP ExifTool package requirements (e.g., >= 10.88).
    

Extension Points

  1. Custom Metadata Mappings

    // Normalize metadata keys (e.g., 'Image::Make' => 'camera_make')
    $normalized = collect($metadata)->mapWithKeys(function ($value, $key) {
        return ["{$key->replace('::', '_')}" => $value];
    })->toArray();
    
  2. Plugin Integration

    • Use ExifTool::addArgument() to pass custom ExifTool arguments:
      $exifTool->addArgument('-config', 'custom_config.txt');
      
  3. Parallel Processing

    $files = ['file1.jpg', 'file2.jpg', 'file3.jpg'];
    $results = collect($files)->map(function ($file) use ($exifTool) {
        return $exifTool->parseFile($file);
    })->toArray();
    

Config Quirks

  • Windows Line Endings
    • Ensure exiftool(-k).exe is in PATH and files use Unix-style line endings if processing logs/configs.
  • Timezone Handling
    • Metadata timestamps may be in UTC. Convert using Carbon:
      $timestamp = Carbon::parse($metadata['EXIF::DateTimeOriginal'])->timezone('America/New_York');
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
althinect/enum-permission
andydefer/laravel-actions
aimeos/prisma
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor