TheFan1968 icon

Bild-Manipulation mit Spatie

TheFan1968 | PRO | 02/28/26 07:51:24 PM UTC | 1 ⭐ | 11338 👁️ | Never ⏰ | [php, laravel, spatie]
PHP |

970 B

|

Source Code

|

1 👍

/

0 👎

use Spatie\Image\Image;
use Spatie\Image\Enums\AlignPosition;
use Spatie\Image\Enums\Unit;
 
Image::load(storage_path('app/public/input.jpg'))
    // 1. Größe anpassen (Fit kombiniert Resize & Crop)
    ->fit(800, 600)
    
    // 2. Text mit Hintergrund hinzufügen
    // Spatie erlaubt es, Text-Eigenschaften in einer Closure zu definieren
    ->text('Ihr Text hier', function($font) {
        $font->file(public_path('fonts/Roboto-Bold.ttf'))
             ->size(40)
             ->color('ffffff')
             ->width(700) // Maximale Breite des Textblocks
             ->align(AlignPosition::Center)
             // Hier tricksen wir: Der Hintergrund wird direkt am Text ausgerichtet
             ->background('rgba(0, 0, 0, 0.6)') 
             ->padding(20); // Abstand zwischen Text und Hintergrundbox
    })
    
    // Position des Textblocks auf dem Gesamtbild
    ->textPosition(AlignPosition::Bottom) 
    
    ->save(storage_path('app/public/output.jpg'));

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎