Skip to content

Commit

Permalink
Merge pull request #99 from mo3et/s3/del-expire-data
Browse files Browse the repository at this point in the history
add getResizeImageSize function in minio
  • Loading branch information
mo3et committed Jul 2, 2024
2 parents a0cbd3c + 88bb5f6 commit e2d44f3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
20 changes: 20 additions & 0 deletions s3/minio/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,23 @@ func resizeImage(img image.Image, maxWidth, maxHeight int) image.Image {
// By default, the original image is returned
return img
}

func getResizeImageSize(img image.Image, maxWidth, maxHeight int) (thumbnailWidth, thumbnailHeight int) {
bounds := img.Bounds()
imgWidth := bounds.Max.X
imgHeight := bounds.Max.Y

// Calculating scaling
scaleWidth := float64(maxWidth) / float64(imgWidth)
scaleHeight := float64(maxHeight) / float64(imgHeight)

scale := scaleWidth
if scaleHeight < scaleWidth {
scale = scaleHeight
}

// Calculate Thumbnail Size
thumbnailWidth = int(float64(imgWidth) * scale)
thumbnailHeight = int(float64(imgHeight) * scale)
return
}
3 changes: 1 addition & 2 deletions s3/minio/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,8 +508,7 @@ func (m *Minio) GetImageThumbnailKey(ctx context.Context, name string) (string,
return "", errs.New("object not image").Wrap()
}

thumbnail := resizeImage(img, info.Width, info.Height)
thumbnailWidth, thumbnailHeight := ImageWidthHeight(thumbnail)
thumbnailWidth, thumbnailHeight := getResizeImageSize(img, info.Width, info.Height)
opt := &s3.Image{
Width: thumbnailWidth,
Height: thumbnailHeight,
Expand Down

0 comments on commit e2d44f3

Please sign in to comment.