@@ -111,64 +111,6 @@ Exif orientation values to correctly display the letter F:
111111 )
112112 }
113113
114- // Transform image orientation based on the given EXIF orientation option:
115- loadImage . transformCoordinates = function ( canvas , options ) {
116- originalTransformCoordinates . call ( loadImage , canvas , options )
117- var orientation = options . orientation
118- if ( ! ( orientation > 1 && orientation < 9 ) ) {
119- return
120- }
121- var ctx = canvas . getContext ( '2d' )
122- var width = canvas . width
123- var height = canvas . height
124- var styleWidth = canvas . style . width
125- var styleHeight = canvas . style . height
126- if ( orientation > 4 ) {
127- canvas . width = height
128- canvas . height = width
129- canvas . style . width = styleHeight
130- canvas . style . height = styleWidth
131- }
132- switch ( orientation ) {
133- case 2 :
134- // horizontal flip
135- ctx . translate ( width , 0 )
136- ctx . scale ( - 1 , 1 )
137- break
138- case 3 :
139- // 180° rotate left
140- ctx . translate ( width , height )
141- ctx . rotate ( Math . PI )
142- break
143- case 4 :
144- // vertical flip
145- ctx . translate ( 0 , height )
146- ctx . scale ( 1 , - 1 )
147- break
148- case 5 :
149- // vertical flip + 90° rotate right
150- ctx . rotate ( 0.5 * Math . PI )
151- ctx . scale ( 1 , - 1 )
152- break
153- case 6 :
154- // 90° rotate right
155- ctx . rotate ( 0.5 * Math . PI )
156- ctx . translate ( 0 , - height )
157- break
158- case 7 :
159- // horizontal flip + 90° rotate right
160- ctx . rotate ( 0.5 * Math . PI )
161- ctx . translate ( width , - height )
162- ctx . scale ( - 1 , 1 )
163- break
164- case 8 :
165- // 90° rotate left
166- ctx . rotate ( - 0.5 * Math . PI )
167- ctx . translate ( - width , 0 )
168- break
169- }
170- }
171-
172114 // Transforms coordinate and dimension options
173115 // based on the given orientation option:
174116 loadImage . getTransformedOptions = function ( img , opts , data ) {
@@ -250,4 +192,62 @@ Exif orientation values to correctly display the letter F:
250192 }
251193 return newOptions
252194 }
195+
196+ // Transform image orientation based on the given EXIF orientation option:
197+ loadImage . transformCoordinates = function ( canvas , options ) {
198+ originalTransformCoordinates . call ( loadImage , canvas , options )
199+ var orientation = options . orientation
200+ if ( ! ( orientation > 1 && orientation < 9 ) ) {
201+ return
202+ }
203+ var ctx = canvas . getContext ( '2d' )
204+ var width = canvas . width
205+ var height = canvas . height
206+ var styleWidth = canvas . style . width
207+ var styleHeight = canvas . style . height
208+ if ( orientation > 4 ) {
209+ canvas . width = height
210+ canvas . height = width
211+ canvas . style . width = styleHeight
212+ canvas . style . height = styleWidth
213+ }
214+ switch ( orientation ) {
215+ case 2 :
216+ // horizontal flip
217+ ctx . translate ( width , 0 )
218+ ctx . scale ( - 1 , 1 )
219+ break
220+ case 3 :
221+ // 180° rotate left
222+ ctx . translate ( width , height )
223+ ctx . rotate ( Math . PI )
224+ break
225+ case 4 :
226+ // vertical flip
227+ ctx . translate ( 0 , height )
228+ ctx . scale ( 1 , - 1 )
229+ break
230+ case 5 :
231+ // vertical flip + 90° rotate right
232+ ctx . rotate ( 0.5 * Math . PI )
233+ ctx . scale ( 1 , - 1 )
234+ break
235+ case 6 :
236+ // 90° rotate right
237+ ctx . rotate ( 0.5 * Math . PI )
238+ ctx . translate ( 0 , - height )
239+ break
240+ case 7 :
241+ // horizontal flip + 90° rotate right
242+ ctx . rotate ( 0.5 * Math . PI )
243+ ctx . translate ( width , - height )
244+ ctx . scale ( - 1 , 1 )
245+ break
246+ case 8 :
247+ // 90° rotate left
248+ ctx . rotate ( - 0.5 * Math . PI )
249+ ctx . translate ( - width , 0 )
250+ break
251+ }
252+ }
253253} )
0 commit comments