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)
8080 break ;
8181
8282 case IMAGETYPE_JPEG :
83- $ this ->source_image = imagecreatefromjpeg ($ filename );
83+ $ this ->source_image = $ this -> imageCreateJpegfromExif ($ filename );
8484 break ;
8585
8686 case IMAGETYPE_PNG :
@@ -94,6 +94,32 @@ public function __construct($filename)
9494
9595 return $ this ->resize ($ this ->getSourceWidth (), $ this ->getSourceHeight ());
9696 }
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+ }
97123
98124 /**
99125 * Saves new image
You can’t perform that action at this time.
0 commit comments