Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[+] Exif Description #453

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@
'url' => '/preview/{fileId}',
'verb' => 'GET'
],
// exif of picture
[
'name' => 'files#exif',
'url' => '/files/exif',
'verb' => 'GET'
],
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The public routes will need the same endpoint

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* Public services
*/
Expand Down
24 changes: 24 additions & 0 deletions controller/files.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@ trait Files {
/** @var ILogger */
private $logger;

/**
* @NoAdminRequired
*
* Returns a exif of picture
*
* @param string $location a path picture
* @return array
*/
public function exif($location){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's best to use the file's ID

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

$filename=\OC\Files\Filesystem::getLocalFile($location);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot use private APIs

$exif = false;
$iptc = false;
if (is_callable('exif_read_data')) {
$exif=@exif_read_data($filename);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that work with encrypted files or files located on external storage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. for external "local" return direct path, for external nonlocal return path to cached file.

}
getimagesize($filename,$info);
if (is_array($info)){
foreach($info as $k => $i){
$iptc[$k]=iptcparse($i);
}
}
return ['exif'=>$exif,'iptc'=>$iptc];
}

/**
* @NoAdminRequired
*
Expand Down
32 changes: 32 additions & 0 deletions js/slideshow.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,38 @@

// check if we moved along while we were loading
if (currentImageId === index) {
// check if not in cache
if (this.images[index].desc===undefined){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to make sure we only send the request when we have a media type which supports meta data

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

var params={location:this.images[index].path}
var url=OC.generateUrl('apps/gallery/files/exif?location={location}', params);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's best to use something like this Gallery.utility.buildGalleryUrl('files', '/exif', params);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildGalleryUrl is defined in galleryutility.js, but its not included in /apps/files.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, you're correct. I keep having to duplicate methods because we don't load too many files on the files side.

$.getJSON(url).then(function(data){
console.log(data);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be removed at the end of the process

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

var d;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer it if the variable is more descriptive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (data){
// IPTC:Description (Picasa, Photoshop, Lightroom)
if (data['iptc']&&data['iptc']['APP13']&&data['iptc']['APP13']['2#120']){
d=data['iptc']['APP13']['2#120'][0];
}
// EXIF:Description (old camera model)
if (!d){
if (data['exif']&&data['exif']['ImageDescription'])
d=data['exif']['ImageDescription'];
}
if (d){
this.images[index].desc=d;
this.controls.show(currentImageId);
this._initControlsAutoFader();
this.container.removeClass('inactive');
}else{
this.images[index].desc='';
}
}
}.bind(this));
}else if (this.images[index].desc){
this.controls.show(currentImageId);
this._initControlsAutoFader();
this.container.removeClass('inactive');
}
var image = this.images[index];
var transparent = this._isTransparent(image.mimeType);
this.controls.showActionButtons(transparent);
Expand Down
7 changes: 6 additions & 1 deletion js/slideshowcontrols.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@
if (this.playing) {
this._setTimeout();
}
this._setName(currentImage.name);
// check exif descr
if (currentImage.desc){
this._setName(currentImage.desc);
}else{
this._setName(currentImage.name);
}
},

/**
Expand Down