changlin.shi
2 years ago
33 changed files with 508 additions and 227 deletions
-
2.github/workflows/container_dev.yml
-
2.github/workflows/container_latest.yml
-
2.github/workflows/container_release1.yml
-
2.github/workflows/container_release2.yml
-
2.github/workflows/container_release3.yml
-
2.github/workflows/container_release4.yml
-
2.github/workflows/container_release5.yml
-
2README.md
-
84go.mod
-
361go.sum
-
6k8s/charts/seaweedfs/templates/filer-statefulset.yaml
-
12k8s/charts/seaweedfs/values.yaml
-
13weed/command/master.go
-
1weed/command/server.go
-
94weed/images/cropping.go
-
17weed/mount/weedfs_dir_mkrm.go
-
9weed/mount/weedfs_link.go
-
11weed/mount/weedfs_symlink.go
-
2weed/s3api/s3_constants/acp_grantee_group.go
-
3weed/server/filer_grpc_server_remote.go
-
3weed/server/filer_server.go
-
2weed/server/filer_server_handlers_read_dir.go
-
2weed/server/filer_server_handlers_write_autochunk.go
-
2weed/shell/command_s3_bucket_list.go
-
1weed/shell/command_volume_fsck.go
-
29weed/shell/command_volume_server_evacuate.go
-
7weed/shell/command_volume_server_evacuate_test.go
-
12weed/stats/metrics.go
-
6weed/storage/needle/needle_read_page.go
-
2weed/storage/needle_map_metric_test.go
-
8weed/storage/volume_read_test.go
-
11weed/topology/node.go
-
21weed/topology/topology.go
361
go.sum
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1,47 +1,47 @@ |
|||
package images |
|||
|
|||
import ( |
|||
"bytes" |
|||
"image" |
|||
"image/gif" |
|||
"image/jpeg" |
|||
"image/png" |
|||
"io" |
|||
|
|||
"github.com/disintegration/imaging" |
|||
|
|||
"github.com/seaweedfs/seaweedfs/weed/glog" |
|||
) |
|||
|
|||
func Cropped(ext string, read io.ReadSeeker, x1, y1, x2, y2 int) (cropped io.ReadSeeker, err error) { |
|||
srcImage, _, err := image.Decode(read) |
|||
if err != nil { |
|||
glog.Error(err) |
|||
return read, err |
|||
} |
|||
|
|||
bounds := srcImage.Bounds() |
|||
if x2 > bounds.Dx() || y2 > bounds.Dy() { |
|||
read.Seek(0, 0) |
|||
return read, nil |
|||
} |
|||
|
|||
rectangle := image.Rect(x1, y1, x2, y2) |
|||
dstImage := imaging.Crop(srcImage, rectangle) |
|||
var buf bytes.Buffer |
|||
switch ext { |
|||
case ".jpg", ".jpeg": |
|||
if err = jpeg.Encode(&buf, dstImage, nil); err != nil { |
|||
glog.Error(err) |
|||
} |
|||
case ".png": |
|||
if err = png.Encode(&buf, dstImage); err != nil { |
|||
glog.Error(err) |
|||
} |
|||
case ".gif": |
|||
if err = gif.Encode(&buf, dstImage, nil); err != nil { |
|||
glog.Error(err) |
|||
} |
|||
} |
|||
return bytes.NewReader(buf.Bytes()), err |
|||
} |
|||
package images |
|||
|
|||
import ( |
|||
"bytes" |
|||
"image" |
|||
"image/gif" |
|||
"image/jpeg" |
|||
"image/png" |
|||
"io" |
|||
|
|||
"github.com/disintegration/imaging" |
|||
|
|||
"github.com/seaweedfs/seaweedfs/weed/glog" |
|||
) |
|||
|
|||
func Cropped(ext string, read io.ReadSeeker, x1, y1, x2, y2 int) (cropped io.ReadSeeker, err error) { |
|||
srcImage, _, err := image.Decode(read) |
|||
if err != nil { |
|||
glog.Error(err) |
|||
return read, err |
|||
} |
|||
|
|||
bounds := srcImage.Bounds() |
|||
if x2 > bounds.Dx() || y2 > bounds.Dy() { |
|||
read.Seek(0, 0) |
|||
return read, nil |
|||
} |
|||
|
|||
rectangle := image.Rect(x1, y1, x2, y2) |
|||
dstImage := imaging.Crop(srcImage, rectangle) |
|||
var buf bytes.Buffer |
|||
switch ext { |
|||
case ".jpg", ".jpeg": |
|||
if err = jpeg.Encode(&buf, dstImage, nil); err != nil { |
|||
glog.Error(err) |
|||
} |
|||
case ".png": |
|||
if err = png.Encode(&buf, dstImage); err != nil { |
|||
glog.Error(err) |
|||
} |
|||
case ".gif": |
|||
if err = gif.Encode(&buf, dstImage, nil); err != nil { |
|||
glog.Error(err) |
|||
} |
|||
} |
|||
return bytes.NewReader(buf.Bytes()), err |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue