@@ -109,17 +109,27 @@ func (t *Transform) Anchor(anchor Anchor) *Transform {
109
109
return t
110
110
}
111
111
112
- // CropOffset sets the target offset from the crop position
113
- func (t * Transform ) CropOffset ( x , y int ) * Transform {
112
+ // CropOffsetX sets the target offset from the crop position
113
+ func (t * Transform ) CropOffsetX ( x int ) * Transform {
114
114
t .tx .CropOffsetX .SetInt (x )
115
+ return t
116
+ }
117
+
118
+ // CropOffsetY sets the target offset from the crop position
119
+ func (t * Transform ) CropOffsetY (y int ) * Transform {
115
120
t .tx .CropOffsetY .SetInt (y )
116
121
return t
117
122
}
118
123
119
- // CropOffsetPercent sets the target offset from the crop position
120
- func (t * Transform ) CropOffsetPercent (x , y float64 ) * Transform {
121
- t .tx .CropOffsetX .SetRelative (x )
122
- t .tx .CropOffsetY .SetRelative (y )
124
+ // CropRelativeOffsetX sets the target offset from the crop position
125
+ func (t * Transform ) CropRelativeOffsetX (x float64 ) * Transform {
126
+ t .tx .CropOffsetX .SetScale (x )
127
+ return t
128
+ }
129
+
130
+ // CropRelativeOffsetY sets the target offset from the crop position
131
+ func (t * Transform ) CropRelativeOffsetY (y float64 ) * Transform {
132
+ t .tx .CropOffsetY .SetScale (y )
123
133
return t
124
134
}
125
135
@@ -186,20 +196,20 @@ func (t *Transform) Stretch() *Transform {
186
196
187
197
// ScaleWidth scales the image by its width proportionally
188
198
func (t * Transform ) ScaleWidth (scale float64 ) * Transform {
189
- t .tx .Width .SetRelative (scale )
199
+ t .tx .Width .SetScale (scale )
190
200
return t
191
201
}
192
202
193
203
// ScaleHeight scales the height of the image proportionally
194
204
func (t * Transform ) ScaleHeight (scale float64 ) * Transform {
195
- t .tx .Height .SetRelative (scale )
205
+ t .tx .Height .SetScale (scale )
196
206
return t
197
207
}
198
208
199
209
// Scale the image
200
210
func (t * Transform ) Scale (scale float64 ) * Transform {
201
- t .tx .Width .SetRelative (scale )
202
- t .tx .Height .SetRelative (scale )
211
+ t .tx .Width .SetScale (scale )
212
+ t .tx .Height .SetScale (scale )
203
213
return t
204
214
}
205
215
@@ -307,7 +317,7 @@ func NewBlackboard(image *ImageRef, p *TransformParams) *Blackboard {
307
317
bb .cropOffsetX = p .CropOffsetX .GetRounded (imageWidth )
308
318
bb .cropOffsetY = p .CropOffsetY .GetRounded (imageHeight )
309
319
310
- if p .Width .Value () == 0 && p .Height .Value () == 0 {
320
+ if p .Width .Value == 0 && p .Height .Value == 0 {
311
321
return bb
312
322
}
313
323
@@ -323,8 +333,8 @@ func NewBlackboard(image *ImageRef, p *TransformParams) *Blackboard {
323
333
bb .targetWidth = roundFloat (ratio (bb .targetHeight , imageHeight ) * float64 (imageWidth ))
324
334
}
325
335
326
- if p .Width .IsRelative () && p .Height .IsRelative () {
327
- sx , sy := p .Width .Value () , p .Height .Value ()
336
+ if p .Width .Relative && p .Height .Relative {
337
+ sx , sy := p .Width .Value , p .Height .Value
328
338
if sx == 0 {
329
339
sx = sy
330
340
} else if sy == 0 {
@@ -610,37 +620,29 @@ func (r *LazyFile) Write(p []byte) (n int, err error) {
610
620
}
611
621
612
622
type Scalar struct {
613
- value float64
614
- relative bool
623
+ Value float64
624
+ Relative bool
615
625
}
616
626
617
627
func (s * Scalar ) SetInt (value int ) {
618
628
s .Set (float64 (value ))
619
629
}
620
630
621
631
func (s * Scalar ) Set (value float64 ) {
622
- s .value = value
623
- s .relative = false
624
- }
625
-
626
- func (s * Scalar ) SetRelative (f float64 ) {
627
- s .value = f
628
- s .relative = true
629
- }
630
-
631
- func (s * Scalar ) IsRelative () bool {
632
- return s .relative
632
+ s .Value = value
633
+ s .Relative = false
633
634
}
634
635
635
- func (s * Scalar ) Value () float64 {
636
- return s .value
636
+ func (s * Scalar ) SetScale (f float64 ) {
637
+ s .Value = f
638
+ s .Relative = true
637
639
}
638
640
639
641
func (s * Scalar ) Get (base int ) float64 {
640
- if s .relative {
641
- return s .value * float64 (base )
642
+ if s .Relative {
643
+ return s .Value * float64 (base )
642
644
}
643
- return s .value
645
+ return s .Value
644
646
}
645
647
646
648
func (s * Scalar ) GetRounded (base int ) int {
0 commit comments