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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
85ab3b39
Commit
85ab3b39
authored
Jan 2, 2012
by
Thomas Tanghus
Browse files
Options
Downloads
Patches
Plain Diff
Modified thumbnail.php to use OC_Image. Cut out 50 loc ;-)
parent
d91a4fca
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/contacts/thumbnail.php
+31
-73
31 additions, 73 deletions
apps/contacts/thumbnail.php
with
31 additions
and
73 deletions
apps/contacts/thumbnail.php
+
31
−
73
View file @
85ab3b39
...
@@ -2,8 +2,8 @@
...
@@ -2,8 +2,8 @@
/**
/**
* ownCloud - Addressbook
* ownCloud - Addressbook
*
*
* @author
Jakob Sack
* @author
Thomas Tanghus
* @copyright 2011
Jakob Sack mail@jakobsack.de
* @copyright 2011
-2012 Thomas Tanghus <thomas@tanghus.net>
*
*
* This library is free software; you can redistribute it and/or
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
...
@@ -26,7 +26,7 @@ OC_Util::checkLoggedIn();
...
@@ -26,7 +26,7 @@ OC_Util::checkLoggedIn();
OC_Util
::
checkAppEnabled
(
'contacts'
);
OC_Util
::
checkAppEnabled
(
'contacts'
);
if
(
!
function_exists
(
'imagecreatefromjpeg'
))
{
if
(
!
function_exists
(
'imagecreatefromjpeg'
))
{
OC_Log
::
write
(
'contacts'
,
'GD module not installed'
,
OC_Log
::
ERROR
);
OC_Log
::
write
(
'contacts'
,
'
thumbnail.php.
GD module not installed'
,
OC_Log
::
DEBUG
);
header
(
'Content-Type: image/png'
);
header
(
'Content-Type: image/png'
);
// TODO: Check if it works to read the file and echo the content.
// TODO: Check if it works to read the file and echo the content.
return
'img/person.png'
;
return
'img/person.png'
;
...
@@ -46,13 +46,16 @@ $l10n = new OC_L10N('contacts');
...
@@ -46,13 +46,16 @@ $l10n = new OC_L10N('contacts');
$card
=
OC_Contacts_VCard
::
find
(
$id
);
$card
=
OC_Contacts_VCard
::
find
(
$id
);
if
(
$card
===
false
){
if
(
$card
===
false
){
echo
$l10n
->
t
(
'Contact could not be found.'
);
OC_Log
::
write
(
'contacts'
,
'thumbnail.php. Contact could not be found.'
,
OC_Log
::
ERROR
);
//echo $l10n->t('Contact could not be found.');
exit
();
exit
();
}
}
// FIXME: Is this check necessary? It just takes up CPU time.
$addressbook
=
OC_Contacts_Addressbook
::
find
(
$card
[
'addressbookid'
]
);
$addressbook
=
OC_Contacts_Addressbook
::
find
(
$card
[
'addressbookid'
]
);
if
(
$addressbook
===
false
||
$addressbook
[
'userid'
]
!=
OC_USER
::
getUser
()){
if
(
$addressbook
===
false
||
$addressbook
[
'userid'
]
!=
OC_USER
::
getUser
()){
echo
$l10n
->
t
(
'This is not your contact.'
);
// This is a weird error, why would it come up? (Better feedback for users?)
OC_Log
::
write
(
'contacts'
,
'thumbnail.php. Wrong contact/addressbook - WTF?'
,
OC_Log
::
ERROR
);
//echo $l10n->t('This is not your contact.'); // This is a weird error, why would it come up? (Better feedback for users?)
exit
();
exit
();
}
}
...
@@ -60,17 +63,14 @@ $content = OC_VObject::parse($card['carddata']);
...
@@ -60,17 +63,14 @@ $content = OC_VObject::parse($card['carddata']);
// invalid vcard
// invalid vcard
if
(
is_null
(
$content
)){
if
(
is_null
(
$content
)){
echo
$l10n
->
t
(
'This card is not RFC compatible.'
);
OC_Log
::
write
(
'contacts'
,
'thumbnail.php. The VCard for ID '
.
$id
.
' is not RFC compatible'
,
OC_Log
::
ERROR
);
getStandardImage
();
exit
();
exit
();
}
}
// define the width and height for the thumbnail
$thumbnail_size
=
23
;
// note that theese dimmensions are considered the maximum dimmension and are not fixed,
// because we have to keep the image ratio intact or it will be deformed
$thumbnail_width
=
23
;
$thumbnail_height
=
23
;
//
Photo :-)
//
Finf the photo from VCard.
foreach
(
$content
->
children
as
$child
){
foreach
(
$content
->
children
as
$child
){
if
(
$child
->
name
==
'PHOTO'
){
if
(
$child
->
name
==
'PHOTO'
){
foreach
(
$child
->
parameters
as
$parameter
){
foreach
(
$child
->
parameters
as
$parameter
){
...
@@ -78,73 +78,31 @@ foreach($content->children as $child){
...
@@ -78,73 +78,31 @@ foreach($content->children as $child){
$mime
=
$parameter
->
value
;
$mime
=
$parameter
->
value
;
}
}
}
}
$data
=
base64_decode
(
$child
->
value
);
$image
=
new
OC_Image
();
$src_img
=
imagecreatefromstring
(
$data
);
if
(
$image
->
loadFromBase64
(
$child
->
value
))
{
if
(
$src_img
!==
false
)
{
if
(
$image
->
centerCrop
())
{
//gets the dimmensions of the image
if
(
$image
->
resize
(
$thumbnail_size
))
{
$width_orig
=
imageSX
(
$src_img
);
if
(
!
$image
())
{
$height_orig
=
imageSY
(
$src_img
);
OC_Log
::
write
(
'contacts'
,
'thumbnail.php. Couldn\'t display thumbnail for ID '
.
$id
,
OC_Log
::
ERROR
);
$ratio_orig
=
$width_orig
/
$height_orig
;
if
(
$thumbnail_width
/
$thumbnail_height
>
$ratio_orig
)
{
$new_height
=
$thumbnail_width
/
$ratio_orig
;
$new_width
=
$thumbnail_width
;
}
else
{
$new_width
=
$thumbnail_height
*
$ratio_orig
;
$new_height
=
$thumbnail_height
;
}
$x_mid
=
$new_width
/
2
;
//horizontal middle
$y_mid
=
$new_height
/
2
;
//vertical middle
$process
=
imagecreatetruecolor
(
round
(
$new_width
),
round
(
$new_height
));
if
(
$process
==
false
)
{
getStandardImage
();
getStandardImage
();
//echo 'Error creating process image: '.$new_width.'x'.$new_height;
OC_Log
::
write
(
'contacts'
,
'Error creating process image for '
.
$id
.
' '
.
$new_width
.
'x'
.
$new_height
,
OC_Log
::
ERROR
);
imagedestroy
(
$process
);
imagedestroy
(
$src_img
);
exit
();
exit
();
}
}
}
else
{
imagecopyresampled
(
$process
,
$src_img
,
0
,
0
,
0
,
0
,
$new_width
,
$new_height
,
$width_orig
,
$height_orig
);
OC_Log
::
write
(
'contacts'
,
'thumbnail.php. Couldn\'t resize thumbnail for ID '
.
$id
,
OC_Log
::
ERROR
);
if
(
$process
==
false
)
{
getStandardImage
();
getStandardImage
();
//echo 'Error resampling process image: '.$new_width.'x'.$new_height;
OC_Log
::
write
(
'contacts'
,
'Error resampling process image for '
.
$id
.
' '
.
$new_width
.
'x'
.
$new_height
,
OC_Log
::
ERROR
);
imagedestroy
(
$process
);
imagedestroy
(
$src_img
);
exit
();
exit
();
}
}
$thumb
=
imagecreatetruecolor
(
$thumbnail_width
,
$thumbnail_height
);
}
else
{
if
(
$process
==
false
)
{
OC_Log
::
write
(
'contacts'
,
'thumbnail.php. Couldn\'t crop thumbnail for ID '
.
$id
,
OC_Log
::
ERROR
);
getStandardImage
();
getStandardImage
();
//echo 'Error creating thumb image: '.$thumbnail_width.'x'.$thumbnail_height;
OC_Log
::
write
(
'contacts'
,
'Error creating thumb image for '
.
$id
.
' '
.
$thumbnail_width
.
'x'
.
$thumbnail_height
,
OC_Log
::
ERROR
);
imagedestroy
(
$process
);
imagedestroy
(
$src_img
);
exit
();
exit
();
}
}
imagecopyresampled
(
$thumb
,
$process
,
0
,
0
,
(
$x_mid
-
(
$thumbnail_width
/
2
)),
(
$y_mid
-
(
$thumbnail_height
/
2
)),
$thumbnail_width
,
$thumbnail_height
,
$thumbnail_width
,
$thumbnail_height
);
if
(
$thumb
!==
false
)
{
header
(
'Content-Type: image/png'
);
imagepng
(
$thumb
);
}
else
{
}
else
{
OC_Log
::
write
(
'contacts'
,
'thumbnail.php. Couldn\'t load image string for ID '
.
$id
,
OC_Log
::
ERROR
);
getStandardImage
();
getStandardImage
();
OC_Log
::
write
(
'contacts'
,
'Error resampling thumb image for '
.
$id
.
' '
.
$thumbnail_width
.
'x'
.
$thumbnail_height
,
OC_Log
::
ERROR
);
exit
();
//echo 'An error occurred resampling thumb.';
}
imagedestroy
(
$thumb
);
imagedestroy
(
$process
);
imagedestroy
(
$src_img
);
}
else
{
getStandardImage
();
}
}
exit
();
exit
();
}
}
}
}
getStandardImage
();
getStandardImage
();
// Not found :-(
//echo $l10n->t('This card does not contain a photo.');
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