File tree Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Expand file tree Collapse file tree 1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ public function __construct($filename)
80
80
break ;
81
81
82
82
case IMAGETYPE_JPEG :
83
- $ this ->source_image = imagecreatefromjpeg ($ filename );
83
+ $ this ->source_image = $ this -> imageCreateJpegfromExif ($ filename );
84
84
break ;
85
85
86
86
case IMAGETYPE_PNG :
@@ -94,6 +94,32 @@ public function __construct($filename)
94
94
95
95
return $ this ->resize ($ this ->getSourceWidth (), $ this ->getSourceHeight ());
96
96
}
97
+
98
+ // http://stackoverflow.com/a/28819866
99
+ public function imageCreateJpegfromExif ($ filename ){
100
+ $ img = imagecreatefromjpeg ($ filename );
101
+ $ exif = exif_read_data ($ filename );
102
+
103
+ if (!$ exif || !isset ($ exif ['Orientation ' ])){
104
+ return $ img ;
105
+ }
106
+
107
+ $ orientation = $ exif ['Orientation ' ];
108
+
109
+ if ($ orientation === 6 || $ orientation === 5 ){
110
+ $ img = imagerotate ($ img , 270 , null );
111
+ } else if ($ orientation === 3 || $ orientation === 4 ){
112
+ $ img = imagerotate ($ img , 180 , null );
113
+ } else if ($ orientation === 8 || $ orientation === 7 ){
114
+ $ img = imagerotate ($ img , 90 , null );
115
+ }
116
+
117
+ if ($ orientation === 5 || $ orientation === 4 || $ orientation === 7 ){
118
+ imageflip ($ img , IMG_FLIP_HORIZONTAL );
119
+ }
120
+
121
+ return $ img ;
122
+ }
97
123
98
124
/**
99
125
* Saves new image
You can’t perform that action at this time.
0 commit comments