Skip to content

Commit d34349f

Browse files
committed
Remove exif image rotation
1 parent 1b0bb81 commit d34349f

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

Lib/BlobFileHandler.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@ public function loadFromFile($filename) {
181181
default: $this->error ("File type must be GIF, PNG, or JPG to resize");
182182
}
183183

184+
// rotate source image based on exif-orientation
185+
$this->fixImageRotation($filename);
186+
184187
}
185188

186189
public function loadFromString($string) {
@@ -300,4 +303,27 @@ public function getImageWith() {
300303
return imagesx($this->resource);
301304
}
302305

306+
protected function fixImageRotation($filename) {
307+
308+
if (! function_exists("exif_read_data")) {
309+
return;
310+
}
311+
312+
$exif = exif_read_data($filename);
313+
314+
if (!empty($exif['Orientation'])) {
315+
switch ($exif['Orientation']) {
316+
case 3:
317+
$this->resource = imagerotate($this->resource, 180, 0);
318+
break;
319+
case 6:
320+
$this->resource = imagerotate($this->resource, -90, 0);
321+
break;
322+
case 8:
323+
$this->resource = imagerotate($this->resource, 90, 0);
324+
break;
325+
}
326+
}
327+
}
328+
303329
}

Model/Behavior/BlobFileBehavior.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function beforeSave(Model $model, $options = array()) {
6767

6868
public function isUploadedFileImage($model,$params) {
6969

70-
$val = array_shift($params);
70+
$val = array_shift($params);
7171

7272
if ( ! empty($val['name']) and empty($val['tmp_name'])) {
7373
return false;
@@ -77,10 +77,10 @@ public function isUploadedFileImage($model,$params) {
7777
return true; // allow empty value
7878
}
7979

80-
$fileHandler = new BlobFileHandler;
81-
$fileHandler->loadFromFile($val['tmp_name']);
80+
$fileHandler = new BlobFileHandler;
81+
$fileHandler->loadFromFile($val['tmp_name']);
8282

83-
return $fileHandler->isImage();
83+
return $fileHandler->isImage();
8484
}
8585

8686
}

0 commit comments

Comments
 (0)