mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-04-25 04:46:24 +02:00
allow percentage sizes
change height and width options to be floats, and interpret values between 0 and 1 to be percentages. For example, an options strings of "0.5x" specifies 50% width and proportional height.
This commit is contained in:
parent
036d0c51c4
commit
cd1112f7ac
4 changed files with 28 additions and 12 deletions
10
data/data.go
10
data/data.go
|
|
@ -12,8 +12,8 @@ import (
|
|||
// Options specifies transformations that can be performed on a
|
||||
// requested image.
|
||||
type Options struct {
|
||||
Width int // requested width, in pixels
|
||||
Height int // requested height, in pixels
|
||||
Width float64 // requested width, in pixels
|
||||
Height float64 // requested height, in pixels
|
||||
|
||||
// If true, resize the image to fit in the specified dimensions. Image
|
||||
// will not be cropped, and aspect ratio will be maintained.
|
||||
|
|
@ -21,7 +21,7 @@ type Options struct {
|
|||
}
|
||||
|
||||
func (o Options) String() string {
|
||||
return fmt.Sprintf("%dx%d", o.Width, o.Height)
|
||||
return fmt.Sprintf("%vx%v", o.Width, o.Height)
|
||||
}
|
||||
|
||||
func ParseOptions(str string) *Options {
|
||||
|
|
@ -40,10 +40,10 @@ func ParseOptions(str string) *Options {
|
|||
}
|
||||
|
||||
if w != "" {
|
||||
o.Width, _ = strconv.Atoi(w)
|
||||
o.Width, _ = strconv.ParseFloat(w, 64)
|
||||
}
|
||||
if h != "" {
|
||||
o.Height, _ = strconv.Atoi(h)
|
||||
o.Height, _ = strconv.ParseFloat(h, 64)
|
||||
}
|
||||
|
||||
for _, part := range parts[1:] {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue