Skip to content

Commit ef7fb10

Browse files
committed
Fix edited image being restored to before edit on image upload.
1 parent 943cbd6 commit ef7fb10

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

core/src/Revolution/Sources/modMediaSource.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
use xPDO\Cache\xPDOCacheManager;
3333
use xPDO\Om\xPDOCriteria;
3434
use xPDO\xPDO;
35+
use MODX\Revolution\modPhpThumb;
3536

3637
/**
3738
* An abstract base class extend to implement loading your League\Flysystem\AbstractAdapter
@@ -1182,7 +1183,27 @@ public function uploadObjectsToContainer($container, array $objects = [])
11821183
}
11831184

11841185
try {
1185-
$this->filesystem->write($newPath, file_get_contents($file['tmp_name']));
1186+
$image_extensions = ['jpg', 'jpeg'];
1187+
$file_extension = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
1188+
1189+
if (in_array($file_extension, $image_extensions)) {
1190+
$exif = @exif_read_data($file['tmp_name']);
1191+
if (!empty($exif['Orientation']) && $exif['Orientation'] > 1) {
1192+
$phpThumb = new modPhpThumb($this->xpdo, []);
1193+
$phpThumb->setSourceFilename($file['tmp_name']);
1194+
$phpThumb->setParameter('ar', 'x');
1195+
if ($phpThumb->GenerateThumbnail()) {
1196+
$image_string = $phpThumb->OutputThumbnailData();
1197+
$this->filesystem->write($newPath, $image_string);
1198+
} else {
1199+
$this->filesystem->write($newPath, file_get_contents($file['tmp_name']));
1200+
}
1201+
} else {
1202+
$this->filesystem->write($newPath, file_get_contents($file['tmp_name']));
1203+
}
1204+
} else {
1205+
$this->filesystem->write($newPath, file_get_contents($file['tmp_name']));
1206+
}
11861207
} catch (FilesystemException | UnableToWriteFile $e) {
11871208
$this->addError('path', $this->xpdo->lexicon('file_err_upload'));
11881209
$this->xpdo->log(modX::LOG_LEVEL_ERROR, $e->getMessage());

0 commit comments

Comments
 (0)