aboutsummaryrefslogtreecommitdiff
path: root/models/image.go
diff options
context:
space:
mode:
Diffstat (limited to 'models/image.go')
-rw-r--r--models/image.go11
1 files changed, 10 insertions, 1 deletions
diff --git a/models/image.go b/models/image.go
index 3eeadb1..03f6d0f 100644
--- a/models/image.go
+++ b/models/image.go
@@ -13,7 +13,7 @@ import (
type ImageSize struct {
gorm.Model
ImageID uint `gorm:"not null;index" json:"-"`
- Image Image `gorm:"foreignKey:ImageID" json:"image"`
+ Image Image `gorm:"foreignKey:ImageID" json:"-"`
SizeType config.ImageSizeType `gorm:"not null;size:50" json:"size_type"`
Width int `gorm:"not null" json:"width"`
Height int `gorm:"not null" json:"height"`
@@ -121,6 +121,15 @@ func (i *Image) GetSize(sizeType config.ImageSizeType) *ImageSize {
return nil
}
+func (i *Image) GetSizeByString(sizeType string) *ImageSize {
+ for _, size := range i.Sizes {
+ if string(size.SizeType) == sizeType {
+ return &size
+ }
+ }
+ return nil
+}
+
func (i *Image) GetOriginalDimensions() string {
if fullSize := i.GetSize(config.ImageSizeTypeOriginal); fullSize != nil {
return fullSize.GetDimensions()