mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-11 19:04:35 +00:00
Crop images optionally after resizing (#125)
This commit is contained in:
@@ -149,6 +149,27 @@ func (e *Image) Resize(ctx context.Context, req *img.ResizeRequest, rsp *img.Res
|
||||
}
|
||||
|
||||
resultImage := imaging.Resize(srcImage, int(req.Width), int(req.Height), imaging.Lanczos)
|
||||
if req.CropOptions != nil {
|
||||
anchor := imaging.Center
|
||||
switch req.CropOptions.Anchor {
|
||||
case "top left":
|
||||
anchor = imaging.TopLeft
|
||||
case "top":
|
||||
anchor = imaging.Top
|
||||
case "top right":
|
||||
anchor = imaging.TopRight
|
||||
case "left":
|
||||
anchor = imaging.Left
|
||||
case "bottom left":
|
||||
anchor = imaging.BottomLeft
|
||||
case "bottom":
|
||||
anchor = imaging.Bottom
|
||||
case "bottom right":
|
||||
anchor = imaging.BottomRight
|
||||
}
|
||||
resultImage = imaging.CropAnchor(resultImage, int(req.Width), int(req.Height),
|
||||
anchor)
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
switch {
|
||||
|
||||
Reference in New Issue
Block a user