-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(thumbnails): add the ability to define custom image processors
- Loading branch information
Showing
17 changed files
with
431 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Enhancement: Thumbnail generation with image processors | ||
|
||
Thumbnails can now be changed during creation, previously the images were always scaled to fit the given frame, | ||
but it could happen that the images were cut off because they could not be placed better due to the aspect ratio. | ||
|
||
This pr introduces the possibility of specifying how the behavior should be, following processors are available | ||
|
||
* resize | ||
* fit | ||
* fill | ||
* thumbnail | ||
|
||
the processor can be applied by adding the processor query param to the request, e.g. `processor=fit`, `processor=fill`, ... | ||
|
||
to find out more how the individual processors work please read https://github.com/disintegration/imaging | ||
|
||
if no processor is provided it behaves the same as before (resize for gif's and thumbnail for all other) | ||
|
||
https://github.com/owncloud/ocis/pull/6992 |
116 changes: 63 additions & 53 deletions
116
protogen/gen/ocis/services/thumbnails/v0/thumbnails.pb.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package thumbnail | ||
|
||
import ( | ||
"image" | ||
"strings" | ||
|
||
"github.com/disintegration/imaging" | ||
) | ||
|
||
// Processor processes the thumbnail by applying different transformations to it. | ||
type Processor interface { | ||
ID() string | ||
Process(img image.Image, width, height int, filter imaging.ResampleFilter) *image.NRGBA | ||
} | ||
|
||
// DefinableProcessor is the most simple processor, it holds a replaceable image converter function. | ||
type DefinableProcessor struct { | ||
Slug string | ||
Converter func(img image.Image, width, height int, filter imaging.ResampleFilter) *image.NRGBA | ||
} | ||
|
||
// ID returns the processor identification. | ||
func (p DefinableProcessor) ID() string { return p.Slug } | ||
|
||
// Process transforms the given image. | ||
func (p DefinableProcessor) Process(img image.Image, width, height int, filter imaging.ResampleFilter) *image.NRGBA { | ||
return p.Converter(img, width, height, filter) | ||
} | ||
|
||
// ProcessorFor returns a matching Processor | ||
func ProcessorFor(id, fileType string) (Processor, error) { | ||
switch strings.ToLower(id) { | ||
case "fit": | ||
return DefinableProcessor{Slug: strings.ToLower(id), Converter: imaging.Fit}, nil | ||
case "resize": | ||
return DefinableProcessor{Slug: strings.ToLower(id), Converter: imaging.Resize}, nil | ||
case "fill": | ||
return DefinableProcessor{Slug: strings.ToLower(id), Converter: func(img image.Image, width, height int, filter imaging.ResampleFilter) *image.NRGBA { | ||
return imaging.Fill(img, width, height, imaging.Center, filter) | ||
}}, nil | ||
case "thumbnail": | ||
return DefinableProcessor{Slug: strings.ToLower(id), Converter: imaging.Thumbnail}, nil | ||
default: | ||
switch strings.ToLower(fileType) { | ||
case typeGif: | ||
return DefinableProcessor{Converter: imaging.Resize}, nil | ||
default: | ||
return DefinableProcessor{Converter: imaging.Thumbnail}, nil | ||
} | ||
} | ||
} |
Oops, something went wrong.