Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
2f86a620
Commit
2f86a620
authored
13 years ago
by
Thomas Tanghus
Browse files
Options
Downloads
Patches
Plain Diff
Added fixOrientation method which rotates the image based on EXIF data.
parent
d80b477a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/image.php
+82
-2
82 additions, 2 deletions
lib/image.php
with
82 additions
and
2 deletions
lib/image.php
+
82
−
2
View file @
2f86a620
...
@@ -42,8 +42,7 @@ function ellipsis($str, $maxlen) {
...
@@ -42,8 +42,7 @@ function ellipsis($str, $maxlen) {
}
}
/**
/**
* Class for image manipulation
* Class for basic image manipulation
* Ideas: imagerotate, chunk_split(base64_encode())
*
*
*/
*/
class
OC_Image
{
class
OC_Image
{
...
@@ -200,6 +199,87 @@ class OC_Image {
...
@@ -200,6 +199,87 @@ class OC_Image {
return
chunk_split
(
base64_encode
(
ob_get_clean
()));
return
chunk_split
(
base64_encode
(
ob_get_clean
()));
}
}
/**
* @brief Fixes orientation based on EXIF data.
* @returns bool.
*/
public
function
fixOrientation
()
{
if
(
!
is_resource
(
self
::
$resource
))
{
OC_Log
::
write
(
'core'
,
'OC_Image::fixOrientation() No image loaded.'
,
OC_Log
::
DEBUG
);
return
false
;
}
if
(
is_null
(
self
::
$filepath
)
||
!
is_readable
(
self
::
$filepath
))
{
OC_Log
::
write
(
'core'
,
'OC_Image::fixOrientation() No readable file path set.'
,
OC_Log
::
DEBUG
);
return
false
;
}
$exif
=
exif_read_data
(
self
::
$filepath
,
'IFD0'
);
if
(
!
$exif
)
{
return
false
;
}
if
(
!
isset
(
$exif
[
'Orientation'
]))
{
return
true
;
// Nothing to fix
}
$o
=
$exif
[
'Orientation'
];
OC_Log
::
write
(
'core'
,
'OC_Image::fixOrientation() Orientation: '
.
$o
,
OC_Log
::
DEBUG
);
$rotate
=
0
;
$flip
=
false
;
switch
(
$o
)
{
case
1
:
$rotate
=
0
;
$flip
=
false
;
break
;
case
2
:
// Not tested
$rotate
=
0
;
$flip
=
true
;
break
;
case
3
:
$rotate
=
180
;
$flip
=
false
;
break
;
case
4
:
// Not tested
$rotate
=
180
;
$flip
=
true
;
break
;
case
5
:
// Not tested
$rotate
=
90
;
$flip
=
true
;
break
;
case
6
:
//$rotate = 90;
$rotate
=
270
;
$flip
=
false
;
break
;
case
7
:
// Not tested
$rotate
=
270
;
$flip
=
true
;
break
;
case
8
:
$rotate
=
270
;
$flip
=
false
;
break
;
}
if
(
$rotate
)
{
$res
=
imagerotate
(
self
::
$resource
,
$rotate
,
-
1
);
if
(
$res
)
{
if
(
imagealphablending
(
$res
,
true
))
{
if
(
imagesavealpha
(
$res
,
true
))
{
self
::
$resource
=
$res
;
return
true
;
}
else
{
OC_Log
::
write
(
'core'
,
'OC_Image::fixOrientation() Error during alphasaving.'
,
OC_Log
::
DEBUG
);
return
false
;
}
}
else
{
OC_Log
::
write
(
'core'
,
'OC_Image::fixOrientation() Error during alphablending.'
,
OC_Log
::
DEBUG
);
return
false
;
}
}
else
{
OC_Log
::
write
(
'core'
,
'OC_Image::fixOrientation() Error during oriention fixing.'
,
OC_Log
::
DEBUG
);
return
false
;
}
}
}
/**
/**
* @brief Loads an image from a local file, a base64 encoded string or a resource created by an imagecreate* function.
* @brief Loads an image from a local file, a base64 encoded string or a resource created by an imagecreate* function.
* @param $imageref The path to a local file, a base64 encoded string or a resource created by an imagecreate* function.
* @param $imageref The path to a local file, a base64 encoded string or a resource created by an imagecreate* function.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment