Skip to content

Commit 86d2fa5

Browse files
author
Bradie Tilley
committed
Add Orientate Option to read exif and orientate automatically
1 parent 9ed9c0e commit 86d2fa5

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

classes/Resizer.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Exception;
1010
use Event;
1111
use File;
12+
use Log;
1213
use Intervention\Image\ImageManagerStatic as Image;
1314
use Validator;
1415
use Illuminate\Support\Str;
@@ -294,7 +295,19 @@ public function initResource()
294295
throw new \Exception('Image file does not exist (not found)');
295296
}
296297

297-
$this->im = $this->original = Image::make($this->image);
298+
// Auto Rotate based on exif data
299+
if ($this->options['orientate'] ?? false) {
300+
try {
301+
$this->im = $this->original = Image::make($this->image)->orientate();
302+
} catch (\Throwable $e) {
303+
Log::debug('Failed to fix orientation for image ' . $this->getImagePath() . ' (Is PHP compiled with `--enable-exif`?)');
304+
}
305+
}
306+
307+
// If no orientation requested (or orientation failed)
308+
if (empty($this->im)) {
309+
$this->im = $this->original = Image::make($this->image);
310+
}
298311
} catch (\Exception $e) {
299312
if ($this->allowDefaultImage) {
300313
$this->setFormatCache([]);

updates/version.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,6 @@
5555
2.2.4:
5656
- Fix exception when directory doesn't exist during cache clear
5757
2.2.5:
58-
- Fix regeneration of permalink images that previously defaulted to 404 image
58+
- Fix regeneration of permalink images that previously defaulted to 404 image
59+
2.3.0:
60+
- Add Orientate Option to read exif and orientate automatically

0 commit comments

Comments
 (0)