欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

Intervention/image text watermark 文字水印 有大用

text — Write text to an image

Description

public Intervention\Image\Image text(string $text, [integer $x, [integer $y, [Closure $callback]]])

Write a text string to the current image at an optional x,y basepoint position. You can define more details like font-size, font-file and alignment via a callback as the fourth parameter.

Parameters

text

The text string that will be written to the image.

x (optional)

x-ordinate defining the basepoint of the first character. Default: 0

y (optional)

y-ordinate defining the basepoint of the first character. Default: 0

callback (optional)

Closure callback on the font object to define more optional details. Use the following methods to pass details. See examples of the callback usage below.

Font File

public Intervention\Image\Font file(string $filepath)

Set path to a True Type Font file or a integer value between 1 and 5 for one of the GD library internal fonts. Default: 1

Font Size

public Intervention\Image\Font size(integer $size)

Set font size in pixels. Font sizing is only available if a font file is set and will be ignored otherwise. Default: 12

Font Color

public Intervention\Image\Font color(mixed $color)

Set color of the text in one of the available color formats. Default: #000000

Horizontal Alignment

public Intervention\Image\Font align(string $align)

Set horizontal text alignment relative to given basepoint. Possible values are left, right and center. Default: left

Vertical Alignment

public Intervention\Image\Font valign(string $valign)

Set vertical text alignment relative to given basepoint. Possible values are top, bottom and middle. Default: bottom

Rotation Angle

public Intervention\Image\Font angle(integer $angle)

Set rotation angle of text in degrees. Text will be rotated counter-clockwise around the vertical and horizontal aligned point. Rotation is only available if a font file is set and will be ignored otherwise. Default: no rotation


Return Values

Instance of Intervention\Image\Image

Examples

// create Image from file
$img = Image::make('public/foo.jpg');

// write text
$img->text('The quick brown fox jumps over the lazy dog.');

// write text at position
$img->text('The quick brown fox jumps over the lazy dog.', 120, 100);

// use callback to define details
$img->text('foo', 0, 0, function($font) {
    $font->file('foo/bar.ttf');
    $font->size(24);
    $font->color('#fdf6e3');
    $font->align('center');
    $font->valign('top');
    $font->angle(45);
});

// draw transparent text
$img->text('foo', 0, 0, function($font) {
    $font->color(array(255, 255, 255, 0.5))
});

来自  http://image.intervention.io/api/text



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.


1 Answer 正确答案

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

    来自  https://stackoverflow.com/questions/43360872/intervention-image-tile-text-watermark?utm_medium=organ...

    普通分类: