Add 'thumbnails/' from commit '2ebf7b2f23af96b3b499c401fe5498a9349403d8'
git-subtree-dir: thumbnails git-subtree-mainline:ccc651a11egit-subtree-split:2ebf7b2f23
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package imgsource
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"image"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/owncloud/ocis-thumbnails/pkg/config"
|
||||
)
|
||||
|
||||
// NewFileSystemSource return a new FileSystem instance
|
||||
func NewFileSystemSource(cfg config.FileSystemSource) FileSystem {
|
||||
return FileSystem{
|
||||
basePath: cfg.BasePath,
|
||||
}
|
||||
}
|
||||
|
||||
// FileSystem is an image source using the local file system
|
||||
type FileSystem struct {
|
||||
basePath string
|
||||
}
|
||||
|
||||
// Get retrieves an image from the filesystem.
|
||||
func (s FileSystem) Get(ctx context.Context, file string) (image.Image, error) {
|
||||
imgPath := filepath.Join(s.basePath, file)
|
||||
f, err := os.Open(filepath.Clean(imgPath))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to load the file %s from %s error %s", file, imgPath, err.Error())
|
||||
}
|
||||
|
||||
img, _, err := image.Decode(f)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return img, nil
|
||||
}
|
||||
Reference in New Issue
Block a user