accept "fit" option

this also relaxes option parsing to never return an error.  In cases
where options are not able to be parsed, they are silently ignored.
This commit is contained in:
Will Norris 2013-12-06 11:01:34 -08:00
parent 805aa606ca
commit 2794d47390
4 changed files with 47 additions and 23 deletions

View file

@ -18,6 +18,14 @@ var emptyOptions = new(data.Options)
// Transform the provided image.
func Transform(img data.Image, opt *data.Options) (*data.Image, error) {
if opt == nil || reflect.DeepEqual(opt, emptyOptions) {
// bail if no transformation was requested
return &img, nil
}
if opt.Width == 0 && opt.Height == 0 {
// TODO(willnorris): Currently, only resize related options are
// supported, so bail if no sizes are specified. Remove this
// check if we ever support non-resizing transformations.
return &img, nil
}
@ -28,8 +36,10 @@ func Transform(img data.Image, opt *data.Options) (*data.Image, error) {
}
// resize
if opt.Width != 0 || opt.Height != 0 {
if opt.Fit {
m = imaging.Fit(m, opt.Width, opt.Height, imaging.Lanczos)
} else {
m = imaging.Resize(m, opt.Width, opt.Height, imaging.Lanczos)
}
// encode image