Skip to content

Commit

Permalink
Merge pull request #97 from mo3et/s3/del-expire-data
Browse files Browse the repository at this point in the history
implement correct get thumbnail size
  • Loading branch information
mo3et authored Jul 2, 2024
2 parents 87f494f + 2add8d4 commit 5eb5dd4
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions s3/minio/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"errors"
"fmt"
"image"
"io"
"net/http"
"net/url"
Expand Down Expand Up @@ -500,8 +501,9 @@ func (m *Minio) FormData(ctx context.Context, name string, size int64, contentTy
}

func (m *Minio) GetImageThumbnailKey(ctx context.Context, name string) (string, error) {
var img image.Image
info, err := m.cache.GetImageObjectKeyInfo(ctx, name, func(ctx context.Context) (info *ImageInfo, err error) {
info, _, err = m.getObjectImageInfo(ctx, name)
info, img, err = m.getObjectImageInfo(ctx, name)
return
})
if err != nil {
Expand All @@ -510,11 +512,15 @@ func (m *Minio) GetImageThumbnailKey(ctx context.Context, name string) (string,
if !info.IsImg {
return "", errs.New("object not image").Wrap()
}

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

cacheKey := filepath.Join(imageThumbnailPath, info.Etag, fmt.Sprintf("image_w%d_h%d.%s", opt.Width, opt.Height, opt.Format))
return cacheKey, nil
}

0 comments on commit 5eb5dd4

Please sign in to comment.