Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
3e53bf4a
Commit
3e53bf4a
authored
12 years ago
by
Johannes Willnecker
Committed by
Jörn Friedrich Dreyer
12 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix for oc-972, oc-1144 and oc-1191
parent
91da4b05
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/gallery/lib/managers.php
+30
-8
30 additions, 8 deletions
apps/gallery/lib/managers.php
lib/image.php
+71
-9
71 additions, 9 deletions
lib/image.php
with
101 additions
and
17 deletions
apps/gallery/lib/managers.php
+
30
−
8
View file @
3e53bf4a
...
@@ -25,6 +25,15 @@ class DatabaseManager {
...
@@ -25,6 +25,15 @@ class DatabaseManager {
}
}
}
}
public
function
setFileData
(
$path
,
$width
,
$height
)
{
$stmt
=
\OCP\DB
::
prepare
(
'INSERT INTO *PREFIX*pictures_images_cache (uid_owner, path, width, height) VALUES (?, ?, ?, ?)'
);
$stmt
->
execute
(
array
(
\OCP\USER
::
getUser
(),
$path
,
$width
,
$height
));
$ret
=
array
(
'path'
=>
$path
,
'width'
=>
$width
,
'height'
=>
$height
);
unset
(
$image
);
$this
->
cache
[
$dir
][
$path
]
=
$ret
;
return
$ret
;
}
public
function
getFileData
(
$path
)
{
public
function
getFileData
(
$path
)
{
$gallery_path
=
\OCP\Config
::
getSystemValue
(
'datadirectory'
)
.
'/'
.
\OC_User
::
getUser
()
.
'/gallery'
;
$gallery_path
=
\OCP\Config
::
getSystemValue
(
'datadirectory'
)
.
'/'
.
\OC_User
::
getUser
()
.
'/gallery'
;
$path
=
$gallery_path
.
$path
;
$path
=
$gallery_path
.
$path
;
...
@@ -39,9 +48,7 @@ class DatabaseManager {
...
@@ -39,9 +48,7 @@ class DatabaseManager {
if
(
!
$image
->
loadFromFile
(
$path
))
{
if
(
!
$image
->
loadFromFile
(
$path
))
{
return
false
;
return
false
;
}
}
$stmt
=
\OCP\DB
::
prepare
(
'INSERT INTO *PREFIX*pictures_images_cache (uid_owner, path, width, height) VALUES (?, ?, ?, ?)'
);
$ret
=
$this
->
setFileData
(
$path
,
$image
->
width
(),
$image
->
height
());
$stmt
->
execute
(
array
(
\OCP\USER
::
getUser
(),
$path
,
$image
->
width
(),
$image
->
height
()));
$ret
=
array
(
'path'
=>
$path
,
'width'
=>
$image
->
width
(),
'height'
=>
$image
->
height
());
unset
(
$image
);
unset
(
$image
);
$this
->
cache
[
$dir
][
$path
]
=
$ret
;
$this
->
cache
[
$dir
][
$path
]
=
$ret
;
return
$ret
;
return
$ret
;
...
@@ -76,7 +83,7 @@ class ThumbnailsManager {
...
@@ -76,7 +83,7 @@ class ThumbnailsManager {
$image
->
fixOrientation
();
$image
->
fixOrientation
();
$ret
=
$image
->
preciseResize
(
floor
((
150
*
$image
->
w
idth
(
))
/
$image
->
height
()),
150
);
$ret
=
$image
->
preciseResize
(
$this
->
getThumbnailW
idth
(
$image
),
$this
->
getThumbnailHeight
(
$image
)
);
if
(
!
$ret
)
{
if
(
!
$ret
)
{
\OC_Log
::
write
(
self
::
TAG
,
'Couldn\'t resize image'
,
\OC_Log
::
ERROR
);
\OC_Log
::
write
(
self
::
TAG
,
'Couldn\'t resize image'
,
\OC_Log
::
ERROR
);
...
@@ -87,13 +94,28 @@ class ThumbnailsManager {
...
@@ -87,13 +94,28 @@ class ThumbnailsManager {
$image
->
save
(
$gallery_path
.
'/'
.
$path
);
$image
->
save
(
$gallery_path
.
'/'
.
$path
);
return
$image
;
return
$image
;
}
}
public
function
getThumbnailWidth
(
$image
)
{
return
floor
((
150
*
$image
->
widthTopLeft
())
/
$image
->
heightTopLeft
());
}
public
function
getThumbnailHeight
(
$image
)
{
return
150
;
}
public
function
getThumbnailInfo
(
$path
)
{
public
function
getThumbnailInfo
(
$path
)
{
$arr
=
DatabaseManager
::
getInstance
()
->
getFileData
(
$path
);
$arr
=
DatabaseManager
::
getInstance
()
->
getFileData
(
$path
);
if
(
!
$arr
)
{
if
(
!
$arr
)
{
$thubnail
=
$this
->
getThumbnail
(
$path
);
if
(
!
\OC_Filesystem
::
file_exists
(
$path
))
{
unset
(
$thubnail
);
\OC_Log
::
write
(
self
::
TAG
,
'File '
.
$path
.
' don\'t exists'
,
\OC_Log
::
WARN
);
$arr
=
DatabaseManager
::
getInstance
()
->
getFileData
(
$path
);
return
false
;
}
$image
=
new
\OC_Image
();
$image
->
loadFromFile
(
\OC_Filesystem
::
getLocalFile
(
$path
));
if
(
!
$image
->
valid
())
{
return
false
;
}
$arr
=
DatabaseManager
::
getInstance
()
->
setFileData
(
$path
,
$this
->
getThumbnailWidth
(
$image
),
$this
->
getThumbnailHeight
(
$image
));
}
}
$ret
=
array
(
'filepath'
=>
$arr
[
'path'
],
$ret
=
array
(
'filepath'
=>
$arr
[
'path'
],
'width'
=>
$arr
[
'width'
],
'width'
=>
$arr
[
'width'
],
...
...
This diff is collapsed.
Click to expand it.
lib/image.php
+
71
−
9
View file @
3e53bf4a
...
@@ -107,6 +107,56 @@ class OC_Image {
...
@@ -107,6 +107,56 @@ class OC_Image {
return
$this
->
valid
()
?
imagesy
(
$this
->
resource
)
:
-
1
;
return
$this
->
valid
()
?
imagesy
(
$this
->
resource
)
:
-
1
;
}
}
/**
* @brief Returns the width when the image orientation is top-left.
* @returns int
*/
public
function
widthTopLeft
()
{
$o
=
$this
->
getOrientation
();
OC_Log
::
write
(
'core'
,
'OC_Image->widthTopLeft() Orientation: '
.
$o
,
OC_Log
::
DEBUG
);
switch
(
$o
)
{
case
-
1
:
case
1
:
case
2
:
// Not tested
case
3
:
case
4
:
// Not tested
return
$this
->
width
();
break
;
case
5
:
// Not tested
case
6
:
case
7
:
// Not tested
case
8
:
return
$this
->
height
();
break
;
}
return
$this
->
width
();
}
/**
* @brief Returns the height when the image orientation is top-left.
* @returns int
*/
public
function
heightTopLeft
()
{
$o
=
$this
->
getOrientation
();
OC_Log
::
write
(
'core'
,
'OC_Image->heightTopLeft() Orientation: '
.
$o
,
OC_Log
::
DEBUG
);
switch
(
$o
)
{
case
-
1
:
case
1
:
case
2
:
// Not tested
case
3
:
case
4
:
// Not tested
return
$this
->
height
();
break
;
case
5
:
// Not tested
case
6
:
case
7
:
// Not tested
case
8
:
return
$this
->
width
();
break
;
}
return
$this
->
height
();
}
/**
/**
* @brief Outputs the image.
* @brief Outputs the image.
* @returns bool
* @returns bool
...
@@ -209,34 +259,46 @@ class OC_Image {
...
@@ -209,34 +259,46 @@ class OC_Image {
/**
/**
* (I'm open for suggestions on better method name ;)
* (I'm open for suggestions on better method name ;)
* @brief
Fixes
orientation based on EXIF data.
* @brief
Get the
orientation based on EXIF data.
* @returns
bool
.
* @returns
The orientation or -1 if no EXIF data is available
.
*/
*/
public
function
fix
Orientation
()
{
public
function
get
Orientation
()
{
if
(
!
is_callable
(
'exif_read_data'
)){
if
(
!
is_callable
(
'exif_read_data'
)){
OC_Log
::
write
(
'core'
,
'OC_Image->fixOrientation() Exif module not enabled.'
,
OC_Log
::
DEBUG
);
OC_Log
::
write
(
'core'
,
'OC_Image->fixOrientation() Exif module not enabled.'
,
OC_Log
::
DEBUG
);
return
false
;
return
-
1
;
}
}
if
(
!
$this
->
valid
())
{
if
(
!
$this
->
valid
())
{
OC_Log
::
write
(
'core'
,
'OC_Image->fixOrientation() No image loaded.'
,
OC_Log
::
DEBUG
);
OC_Log
::
write
(
'core'
,
'OC_Image->fixOrientation() No image loaded.'
,
OC_Log
::
DEBUG
);
return
false
;
return
-
1
;
}
}
if
(
is_null
(
$this
->
filepath
)
||
!
is_readable
(
$this
->
filepath
))
{
if
(
is_null
(
$this
->
filepath
)
||
!
is_readable
(
$this
->
filepath
))
{
OC_Log
::
write
(
'core'
,
'OC_Image->fixOrientation() No readable file path set.'
,
OC_Log
::
DEBUG
);
OC_Log
::
write
(
'core'
,
'OC_Image->fixOrientation() No readable file path set.'
,
OC_Log
::
DEBUG
);
return
false
;
return
-
1
;
}
}
$exif
=
@
exif_read_data
(
$this
->
filepath
,
'IFD0'
);
$exif
=
@
exif_read_data
(
$this
->
filepath
,
'IFD0'
);
if
(
!
$exif
)
{
if
(
!
$exif
)
{
return
false
;
return
-
1
;
}
}
if
(
!
isset
(
$exif
[
'Orientation'
]))
{
if
(
!
isset
(
$exif
[
'Orientation'
]))
{
return
true
;
// Nothing to fix
return
-
1
;
}
}
$o
=
$exif
[
'Orientation'
];
return
$exif
[
'Orientation'
];
}
/**
* (I'm open for suggestions on better method name ;)
* @brief Fixes orientation based on EXIF data.
* @returns bool.
*/
public
function
fixOrientation
()
{
$o
=
$this
->
getOrienation
();
OC_Log
::
write
(
'core'
,
'OC_Image->fixOrientation() Orientation: '
.
$o
,
OC_Log
::
DEBUG
);
OC_Log
::
write
(
'core'
,
'OC_Image->fixOrientation() Orientation: '
.
$o
,
OC_Log
::
DEBUG
);
$rotate
=
0
;
$rotate
=
0
;
$flip
=
false
;
$flip
=
false
;
switch
(
$o
)
{
switch
(
$o
)
{
case
-
1
:
return
false
;
//Nothing to fix
break
;
case
1
:
case
1
:
$rotate
=
0
;
$rotate
=
0
;
$flip
=
false
;
$flip
=
false
;
...
...
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