MCPcopy
hub / github.com/willnorris/imageproxy / exifOrientation

Function exifOrientation

transform.go:222–270  ·  view source on GitHub ↗

read EXIF orientation tag from r and adjust opt to orient image correctly.

(r io.Reader)

Source from the content-addressed store, hash-verified

220
221// read EXIF orientation tag from r and adjust opt to orient image correctly.
222func exifOrientation(r io.Reader) (opt Options) {
223 // Exif Orientation Tag values
224 // http://sylvana.net/jpegcrop/exif_orientation.html
225 const (
226 topLeftSide = 1
227 topRightSide = 2
228 bottomRightSide = 3
229 bottomLeftSide = 4
230 leftSideTop = 5
231 rightSideTop = 6
232 rightSideBottom = 7
233 leftSideBottom = 8
234 )
235
236 ex, err := exif.Decode(r)
237 if err != nil {
238 return opt
239 }
240 tag, err := ex.Get(exif.Orientation)
241 if err != nil {
242 return opt
243 }
244 orient, err := tag.Int(0)
245 if err != nil {
246 return opt
247 }
248
249 switch orient {
250 case topLeftSide:
251 // do nothing
252 case topRightSide:
253 opt.FlipHorizontal = true
254 case bottomRightSide:
255 opt.Rotate = 180
256 case bottomLeftSide:
257 opt.FlipVertical = true
258 case leftSideTop:
259 opt.Rotate = 90
260 opt.FlipVertical = true
261 case rightSideTop:
262 opt.Rotate = -90
263 case rightSideBottom:
264 opt.Rotate = 90
265 opt.FlipHorizontal = true
266 case leftSideBottom:
267 opt.Rotate = 90
268 }
269 return opt
270}
271
272// transformImage modifies the image m based on the transformations specified
273// in opt.

Callers 1

TransformFunction · 0.85

Calls 1

GetMethod · 0.65

Tested by

no test coverage detected