Skip to content

Commit

Permalink
add document
Browse files Browse the repository at this point in the history
  • Loading branch information
cccaimingjian committed Oct 13, 2022
1 parent 575f52f commit ef9feba
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 2 deletions.
87 changes: 85 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,92 @@ composer require cccaimingjian/laravel-image-watermark -vvv

## Usage

TODO
```
$maker = new Maker();
$maker->setInputFilePath('PATH_TO_YOUR_IMAGE');
```
or
```
$maker = new Maker('PATH_TO_YOUR_IMAGE');
```
or
```
$image = imagecreatefromstring($string);
$image = imagecreatefromjpeg($filename);
...
$maker = new Maker();
$maker->setImage($image);
```

### No.2
Set the watermark characters you want to add,and font file you want to use
然后,设置你要添加的水印字符,并且指定字体文件
```
$maker->setWatermarkString('WATERMARK_STRING_HERE');
$maker->setWatermarkFont('PATH_TO_YOUR_FONT_FILE');
```
### No.3
Set the watermark style
设置水印样式
+ Set angle, defult 15 degrees
设置角度
```
$maker->setAngle(10);
```
+ Set font size, defult 10
设置字体大小
```
$maker->setFontSize(50);
```
+ Set watermark color
设置水印颜色
```
$maker->setWatermarkColor(0xFF0000);
```
+ Set the interval
设置间隔
When setting the horizontal interval, please evaluate the length of the watermark content
When setting the vertical interval, please evaluate the angle of the watermark content
在设置横向间隔的时候,请评估水印内容的长度
在设置纵向间隔的时候,请评估水印内容的角度
```
$maker->setWatermarkWidthInterval(100);
$maker->setWatermarkHeightInterval(50);
```
### No.4
Draw watermark
画水印
```
$maker->drawWatermark();
```
### No.5
Get the watermarked image
获取画了水印的图片
+ Get the watermarked image data directly
直接获取打了水印的图片

Get the watermarked image data content, JPG format
获取带水印的图片数据内容,JPG格式
`$content = $maker->encodeToJPG();`

Get the watermarked image data content, PNG format
获取带水印的图片数据内容,PNG格式
`$content = $maker->encodeToPNG();`

Save the watermarked image
保存图片到指定路径
`$maker->encodeToJPG('PATH_TO_SAVE');`
`$maker->encodeToPNG('PATH_TO_SAVE');`

Get the watermarked image before GD's function imageXXX()
You can encode into other formats or perform other operations by yourself
获取GD imageXXX()之前的资源,你可以自己编码成其他格式或进行其他操作
```
$image = $maker->getGdImage();
imagebmp($image,'PATH'); //encode to bmp.
...
```

模版来源与超哥的项目,如果你喜欢超哥的项目并想支持他,[点击这里 :heart:](https://github.com/sponsors/overtrue)
## PHP 扩展包开发

> 想知道如何从零开始构建 PHP 扩展包?
Expand Down
16 changes: 16 additions & 0 deletions src/Maker.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,20 @@ protected function loadPicture()
$this->pic_h = imagesy($this->image);
return true;
}

/**
* @return null|GdImage
*/
public function getImage()
{
return $this->image;
}

/**
* @param GdImage|null $image
*/
public function setImage($image): void
{
$this->image = $image;
}
}

0 comments on commit ef9feba

Please sign in to comment.