Search code examples
imagelaravel-5intervention

Intervention Image: Tile text watermark


I am using Intervention Image in my Laravel 5.3 for image manipulation, i want to add tile text watermark to an image.

example: enter image description here

$img = Image::make(storage_path('app'.DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.$media->file_path));
// use callback to define details
$width = $img->width();
$height = $img->height();

        $data = $img->text($watermark, 15, 25, function($font) {
                    $font->file(public_path('../fonts/Xerox Serif Wide.ttf'));
                    $font->size(36);
                    $font->color(array(0,0,0, 0.3));
                    $font->align('center');
                    $font->valign('top');
                    $font->angle(45);
                })

but its not working it put a single line with angle given, where as i want text to be repeated until it reaches end of the image.

Thanks.


Solution

  • I don't know if you still need it :) any way i make it. but make user fill padding x,y between text and angle

        $x = 0;
    
     while ($x < $image->width()) {
           $y = 0;
    
           while($y < $image->height()) {
    
             $image->text($watermark->text_text, $x, $y, function($font) use($watermark,$colorhsva,$fontn) {
                         $font->file(public_path('fonts/'.$fontn));
                         $font->size($watermark->text_font_size);
                         $font->color($colorhsva);
                         $font->align($watermark->text_align);
                         $font->valign($watermark->text_valign);
                         $font->angle($watermark->text_angle);
                     });
    
    
                 $y += $watermark->text_distanceyposition;
           }
    
           $x +=$watermark->text_distancexposition;
     }
    

    while text_text = "the user text"

    fontn = the font which user select

    $watermark->text_distanceyposition = y padding form each repeat

    $watermark->text_distancexposition = x padding form each repeat

    colorhsva = color array RGBA;

    $watermark->text_angle = angle 30 in your case

    hope it will help you