mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-09 07:28:44 -07:00
feat(docs): add force resize example
This commit is contained in:
parent
0bff28381f
commit
fa55264a97
2 changed files with 29 additions and 0 deletions
19
README.md
19
README.md
|
|
@ -156,6 +156,25 @@ if bimg.NewImage(newImage).Type() == "png" {
|
|||
}
|
||||
```
|
||||
|
||||
#### Force resize
|
||||
|
||||
```go
|
||||
buffer, err := bimg.Read("image.jpg")
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
|
||||
newImage, err := bimg.NewImage(buffer).ForceResize(1000, 500)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
}
|
||||
|
||||
size := bimg.Size(newImage)
|
||||
if size.Width != 1000 || size.Height != 500 {
|
||||
fmt.Fprintln(os.Stderr, "Incorrect image size")
|
||||
}
|
||||
```
|
||||
|
||||
#### Custom options
|
||||
|
||||
See [Options](https://godoc.org/github.com/h2non/bimg#Options) struct to discover all the available fields
|
||||
|
|
|
|||
10
image.go
10
image.go
|
|
@ -14,6 +14,16 @@ func (i *Image) Resize(width, height int) ([]byte, error) {
|
|||
return i.Process(options)
|
||||
}
|
||||
|
||||
// Force resize with custom size (aspect ratio won't be maintained)
|
||||
func (i *Image) ForceResize(width, height int) ([]byte, error) {
|
||||
options := Options{
|
||||
Width: width,
|
||||
Height: height,
|
||||
Force: true,
|
||||
}
|
||||
return i.Process(options)
|
||||
}
|
||||
|
||||
// Resize the image to fixed width and height with additional crop transformation
|
||||
func (i *Image) ResizeAndCrop(width, height int) ([]byte, error) {
|
||||
options := Options{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue