mirror of
https://github.com/vichan-devel/vichan.git
synced 2024-11-27 17:00:52 +01:00
Automatically rotate and mirror images based on EXIF orientation (only compatiable with "convert" option selected at the moment)
This commit is contained in:
parent
cd81ae8ea5
commit
a44e0571bc
75
post.php
75
post.php
@ -421,6 +421,81 @@ if (isset($_POST['delete'])) {
|
||||
error($config['error']['maxsize']);
|
||||
}
|
||||
|
||||
// The following code corrects the image orientation based on EXIF.
|
||||
// Currently only works with the 'convert' option selected but it could easily be expanded to work with the rest if you can be bothered.
|
||||
if ($config['thumb_method'] == 'convert') {
|
||||
if ($post['extension'] == 'jpg' || $post['extension'] == 'jpeg') {
|
||||
$exif = exif_read_data($upload);
|
||||
if (isset($exif['Orientation'])) {
|
||||
switch($exif['Orientation']) {
|
||||
case 1:
|
||||
// Normal
|
||||
$args = false;
|
||||
break;
|
||||
case 2:
|
||||
// 888888
|
||||
// 88
|
||||
// 8888
|
||||
// 88
|
||||
// 88
|
||||
|
||||
$args = '-flop';
|
||||
break;
|
||||
case 3:
|
||||
|
||||
// 88
|
||||
// 88
|
||||
// 8888
|
||||
// 88
|
||||
// 888888
|
||||
|
||||
$args = '-flip -flop';
|
||||
break;
|
||||
case 4:
|
||||
// 88
|
||||
// 88
|
||||
// 8888
|
||||
// 88
|
||||
// 888888
|
||||
|
||||
$args = '-flip';
|
||||
break;
|
||||
case 5:
|
||||
// 8888888888
|
||||
// 88 88
|
||||
// 88
|
||||
|
||||
$args = '-rotate 90 -flop';
|
||||
break;
|
||||
case 6:
|
||||
// 88
|
||||
// 88 88
|
||||
// 8888888888
|
||||
|
||||
$args = '-rotate 90';
|
||||
break;
|
||||
case 7:
|
||||
// 88
|
||||
// 88 88
|
||||
// 8888888888
|
||||
|
||||
$args = '-rotate "-90" -flop';
|
||||
break;
|
||||
case 8:
|
||||
// 8888888888
|
||||
// 88 88
|
||||
// 88
|
||||
|
||||
$args = '-rotate "-90"';
|
||||
break;
|
||||
}
|
||||
|
||||
if ($args)
|
||||
shell_exec('convert ' . escapeshellarg($upload) . ' ' . $args . ' ' . escapeshellarg($upload));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create image object
|
||||
$image = new Image($upload, $post['extension']);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user