MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / RotateAndFlip

Method RotateAndFlip

processing/gravity.go:88–156  ·  view source on GitHub ↗

RotateAndFlip rotates and flips the gravity options so that they correspond to the image before rotation and flipping. By design, rotation and flipping are applied before cropping. But for performance reasons, we do cropping before rotation and flipping. So we need to adjust gravity options accordi

(angle int, flipX, flipY bool)

Source from the content-addressed store, hash-verified

86// as rotating/flipping the image first and then cropping
87// with the original gravity options.
88func (g *GravityOptions) RotateAndFlip(angle int, flipX, flipY bool) {
89 angle %= 360
90
91 if flipX {
92 if gt, ok := gravityTypesFlipXMap[g.Type]; ok {
93 g.Type = gt
94 }
95
96 switch g.Type {
97 case GravityCenter, GravityNorth, GravitySouth:
98 g.X = -g.X
99 case GravityFocusPoint:
100 g.X = 1.0 - g.X
101 }
102 }
103
104 if flipY {
105 if gt, ok := gravityTypesFlipYMap[g.Type]; ok {
106 g.Type = gt
107 }
108
109 switch g.Type {
110 case GravityCenter, GravityEast, GravityWest:
111 g.Y = -g.Y
112 case GravityFocusPoint:
113 g.Y = 1.0 - g.Y
114 }
115 }
116
117 if angle > 0 {
118 if rotMap := gravityTypesRotationMap[angle]; rotMap != nil {
119 if gt, ok := rotMap[g.Type]; ok {
120 g.Type = gt
121 }
122
123 switch angle {
124 case 90:
125 switch g.Type {
126 case GravityCenter, GravityEast, GravityWest:
127 g.X, g.Y = g.Y, -g.X
128 case GravityFocusPoint:
129 g.X, g.Y = g.Y, 1.0-g.X
130 default:
131 g.X, g.Y = g.Y, g.X
132 }
133 case 180:
134 switch g.Type {
135 case GravityCenter:
136 g.X, g.Y = -g.X, -g.Y
137 case GravityNorth, GravitySouth:
138 g.X = -g.X
139 case GravityEast, GravityWest:
140 g.Y = -g.Y
141 case GravityFocusPoint:
142 g.X, g.Y = 1.0-g.X, 1.0-g.Y
143 }
144 case 270:
145 switch g.Type {

Callers 1

cropMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected