From 99c553d0692e5f07ea7bebff301392241f12e82f Mon Sep 17 00:00:00 2001 From: 0xb0ba Date: Tue, 27 Oct 2015 16:09:39 +0500 Subject: [PATCH 1/8] [+] Exif Description --- appinfo/routes.php | 6 ++++++ js/slideshow.js | 32 ++++++++++++++++++++++++++++++++ js/slideshowcontrols.js | 7 ++++++- lib/Controller/Files.php | 24 ++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 7c968905c..02869e576 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -96,6 +96,12 @@ 'url' => '/preview/{fileId}', 'verb' => 'GET' ], + // exif of picture + [ + 'name' => 'files#exif', + 'url' => '/files/exif', + 'verb' => 'GET' + ], /** * Public services */ diff --git a/js/slideshow.js b/js/slideshow.js index 1ddf367c4..13f3a9586 100644 --- a/js/slideshow.js +++ b/js/slideshow.js @@ -113,6 +113,38 @@ // check if we moved along while we were loading if (currentImageId === index) { + // check if not in cache + if (this.images[index].desc===undefined){ + var params={location:this.images[index].path} + var url=OC.generateUrl('apps/gallery/files/exif?location={location}', params); + $.getJSON(url).then(function(data){ + console.log(data); + var d; + 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, Gallery.token, image.permissions); diff --git a/js/slideshowcontrols.js b/js/slideshowcontrols.js index a27452413..61636bcc3 100644 --- a/js/slideshowcontrols.js +++ b/js/slideshowcontrols.js @@ -97,7 +97,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); + } }, /** diff --git a/lib/Controller/Files.php b/lib/Controller/Files.php index 7e9cf60bb..760036539 100644 --- a/lib/Controller/Files.php +++ b/lib/Controller/Files.php @@ -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){ + $filename=\OC\Files\Filesystem::getLocalFile($location); + $exif = false; + $iptc = false; + if (is_callable('exif_read_data')) { + $exif=@exif_read_data($filename); + } + getimagesize($filename,$info); + if (is_array($info)){ + foreach($info as $k => $i){ + $iptc[$k]=iptcparse($i); + } + } + return ['exif'=>$exif,'iptc'=>$iptc]; + } + /** * @NoAdminRequired * From 2cde812646c9f418e4e069cdefaeaf847c482b07 Mon Sep 17 00:00:00 2001 From: 0xb0ba Date: Wed, 28 Oct 2015 01:34:29 +0500 Subject: [PATCH 2/8] comments from oparoz --- appinfo/routes.php | 8 +++++++- js/gallery.js | 2 +- js/slideshow.js | 18 ++++++++++-------- lib/Controller/Files.php | 19 ++++++++++--------- 4 files changed, 28 insertions(+), 19 deletions(-) diff --git a/appinfo/routes.php b/appinfo/routes.php index 02869e576..7fb222349 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -99,7 +99,7 @@ // exif of picture [ 'name' => 'files#exif', - 'url' => '/files/exif', + 'url' => '/files/exif/{fileId}', 'verb' => 'GET' ], /** @@ -131,6 +131,12 @@ 'url' => '/preview.public/{fileId}', 'verb' => 'GET' ], + // exif of picture + [ + 'name' => 'files_public#exif', + 'url' => '/files.public/exif/{fileId}', + 'verb' => 'GET' + ], /** * API */ diff --git a/js/gallery.js b/js/gallery.js index ac0062c15..19b389792 100644 --- a/js/gallery.js +++ b/js/gallery.js @@ -297,7 +297,7 @@ return { name: name, path: image.path, - file: image.fileId, + fileId: image.fileId, mimeType: image.mimeType, permissions: image.permissions, url: previewUrl, diff --git a/js/slideshow.js b/js/slideshow.js index 13f3a9586..f24219169 100644 --- a/js/slideshow.js +++ b/js/slideshow.js @@ -113,25 +113,26 @@ // check if we moved along while we were loading if (currentImageId === index) { + if (this.images[index].mimeType === 'image/jpeg' || this.images[index].mimeType === 'image/tiff'){ // check if not in cache if (this.images[index].desc===undefined){ - var params={location:this.images[index].path} - var url=OC.generateUrl('apps/gallery/files/exif?location={location}', params); + var params={fileid:this.images[index].fileId} + var url=OC.generateUrl('apps/gallery/files/exif/{fileid}', params); $.getJSON(url).then(function(data){ console.log(data); - var d; + var desc; 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]; + desc=data['iptc']['APP13']['2#120'][0]; } // EXIF:Description (old camera model) - if (!d){ + if (!desc){ if (data['exif']&&data['exif']['ImageDescription']) - d=data['exif']['ImageDescription']; + desc=data['exif']['ImageDescription']; } - if (d){ - this.images[index].desc=d; + if (desc){ + this.images[index].desc=desc; this.controls.show(currentImageId); this._initControlsAutoFader(); this.container.removeClass('inactive'); @@ -145,6 +146,7 @@ this._initControlsAutoFader(); this.container.removeClass('inactive'); } + } var image = this.images[index]; var transparent = this._isTransparent(image.mimeType); this.controls.showActionButtons(transparent, Gallery.token, image.permissions); diff --git a/lib/Controller/Files.php b/lib/Controller/Files.php index 760036539..4443320ff 100644 --- a/lib/Controller/Files.php +++ b/lib/Controller/Files.php @@ -53,21 +53,22 @@ trait Files { * @param string $location a path picture * @return array */ - public function exif($location){ - $filename=\OC\Files\Filesystem::getLocalFile($location); - $exif = false; + public function exif($fileId){ + $path=\OC\Files\Filesystem::getPath($fileId); + $filename=\OC\Files\Filesystem::getLocalFile($path); + $exif = false; $iptc = false; if (is_callable('exif_read_data')) { $exif=@exif_read_data($filename); } - getimagesize($filename,$info); - if (is_array($info)){ - foreach($info as $k => $i){ - $iptc[$k]=iptcparse($i); + getimagesize($filename,$blocks); + if (is_array($blocks)){ + foreach($blocks as $key => $block){ + $iptc[$key]=iptcparse($block); } } - return ['exif'=>$exif,'iptc'=>$iptc]; - } + return ['exif'=>$exif,'iptc'=>$iptc]; + } /** * @NoAdminRequired From bca07c70a5b2f388768bff6a4c7fbf472e99d983 Mon Sep 17 00:00:00 2001 From: 0xb0ba Date: Wed, 28 Oct 2015 01:41:27 +0500 Subject: [PATCH 3/8] remove debug --- js/slideshow.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/slideshow.js b/js/slideshow.js index f24219169..bcf91d807 100644 --- a/js/slideshow.js +++ b/js/slideshow.js @@ -119,7 +119,6 @@ var params={fileid:this.images[index].fileId} var url=OC.generateUrl('apps/gallery/files/exif/{fileid}', params); $.getJSON(url).then(function(data){ - console.log(data); var desc; if (data){ // IPTC:Description (Picasa, Photoshop, Lightroom) From faa6ca0cdce3f920a0785a75daa187be8fe63813 Mon Sep 17 00:00:00 2001 From: 0xb0ba Date: Wed, 28 Oct 2015 11:20:37 +0500 Subject: [PATCH 4/8] Node API here instead of a private API --- lib/Controller/Files.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Controller/Files.php b/lib/Controller/Files.php index 4443320ff..dabeb2b35 100644 --- a/lib/Controller/Files.php +++ b/lib/Controller/Files.php @@ -54,8 +54,10 @@ trait Files { * @return array */ public function exif($fileId){ - $path=\OC\Files\Filesystem::getPath($fileId); - $filename=\OC\Files\Filesystem::getLocalFile($path); + $file = $this->downloadService->getResourceFromId($fileId); + $path=$file->getInternalPath(); + $storage=$file->getStorage(); + $filename=$storage->getLocalFile($path); $exif = false; $iptc = false; if (is_callable('exif_read_data')) { From 6ccfb7c5a9a0bdb26b04d70035cc556c379f27db Mon Sep 17 00:00:00 2001 From: 0xb0ba Date: Thu, 29 Oct 2015 11:53:48 +0500 Subject: [PATCH 5/8] 3 line for description --- css/slideshow.css | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/css/slideshow.css b/css/slideshow.css index 61a1dd034..65fb97b4e 100644 --- a/css/slideshow.css +++ b/css/slideshow.css @@ -134,10 +134,14 @@ bottom: 18px; z-index: 1099; width: 100%; + height: 75px; } #slideshow > .name .title { - padding: 0 50px 3px; + position: absolute; + bottom: 0; + width: 100%; + padding: 0 1% 3px; text-align: center; color: #fff; text-shadow: 1px 1px 4px #333, 1px -1px 4px #333, -1px 1px 4px #333, -1px -1px 4px #333; @@ -146,6 +150,7 @@ text-overflow: ellipsis; overflow: hidden; white-space: nowrap; + filter: alpha(opacity=75); opacity: .75; } From ac24334d7bafc89bd6231581c12ce90e69d80621 Mon Sep 17 00:00:00 2001 From: 0xb0ba Date: Mon, 2 Nov 2015 14:52:46 +0500 Subject: [PATCH 6/8] description for public galleries --- js/slideshow.js | 7 +++++-- lib/Controller/FilesPublicController.php | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/js/slideshow.js b/js/slideshow.js index bcf91d807..f0bd1276f 100644 --- a/js/slideshow.js +++ b/js/slideshow.js @@ -116,8 +116,11 @@ if (this.images[index].mimeType === 'image/jpeg' || this.images[index].mimeType === 'image/tiff'){ // check if not in cache if (this.images[index].desc===undefined){ - var params={fileid:this.images[index].fileId} - var url=OC.generateUrl('apps/gallery/files/exif/{fileid}', params); + if (window.galleryFileAction){ + var url = window.galleryFileAction.buildGalleryUrl('files', '/exif/'+this.images[index].fileId,{}); + }else{ + var url = window.Gallery.utility.buildGalleryUrl('files', '/exif/'+this.images[index].fileId,{}); + } $.getJSON(url).then(function(data){ var desc; if (data){ diff --git a/lib/Controller/FilesPublicController.php b/lib/Controller/FilesPublicController.php index a34b6b041..93e5079ec 100644 --- a/lib/Controller/FilesPublicController.php +++ b/lib/Controller/FilesPublicController.php @@ -22,6 +22,18 @@ */ class FilesPublicController extends FilesController { + /** + * @PublicPage + * + * Returns a exif of picture + * + * @param string $location a path picture + * @return array + */ + public function exif($fileId){ + return parent::exif($fileId); + } + /** * @PublicPage * From b1254ed87f84dd53850c91542156744583c41227 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylvain=20Veyri=C3=A9?= Date: Sun, 8 Apr 2018 13:32:26 +0200 Subject: [PATCH 7/8] Should now use getFile(id) --- lib/Controller/Files.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Controller/Files.php b/lib/Controller/Files.php index dabeb2b35..4b01a52f7 100644 --- a/lib/Controller/Files.php +++ b/lib/Controller/Files.php @@ -54,7 +54,7 @@ trait Files { * @return array */ public function exif($fileId){ - $file = $this->downloadService->getResourceFromId($fileId); + $file = $this->downloadService->getFile($fileId); $path=$file->getInternalPath(); $storage=$file->getStorage(); $filename=$storage->getLocalFile($path); From 19fcc6b7ed8579c0a7428bd693b7ebd139e22647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sylvain=20Veyri=C3=A9?= Date: Sun, 8 Apr 2018 14:27:15 +0200 Subject: [PATCH 8/8] EXIF: code format --- js/slideshow.js | 22 +++++++++++----------- js/slideshowcontrols.js | 4 ++-- lib/Controller/Files.php | 6 +++--- lib/Controller/FilesPublicController.php | 2 +- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/js/slideshow.js b/js/slideshow.js index f0bd1276f..04c46ea40 100644 --- a/js/slideshow.js +++ b/js/slideshow.js @@ -113,37 +113,37 @@ // check if we moved along while we were loading if (currentImageId === index) { - if (this.images[index].mimeType === 'image/jpeg' || this.images[index].mimeType === 'image/tiff'){ + if (this.images[index].mimeType === 'image/jpeg' || this.images[index].mimeType === 'image/tiff') { // check if not in cache - if (this.images[index].desc===undefined){ - if (window.galleryFileAction){ + if (this.images[index].desc===undefined) { + if (window.galleryFileAction) { var url = window.galleryFileAction.buildGalleryUrl('files', '/exif/'+this.images[index].fileId,{}); - }else{ + } else { var url = window.Gallery.utility.buildGalleryUrl('files', '/exif/'+this.images[index].fileId,{}); } - $.getJSON(url).then(function(data){ + $.getJSON(url).then(function(data) { var desc; - if (data){ + if (data) { // IPTC:Description (Picasa, Photoshop, Lightroom) - if (data['iptc']&&data['iptc']['APP13']&&data['iptc']['APP13']['2#120']){ + if (data['iptc']&&data['iptc']['APP13']&&data['iptc']['APP13']['2#120']) { desc=data['iptc']['APP13']['2#120'][0]; } // EXIF:Description (old camera model) - if (!desc){ + if (!desc) { if (data['exif']&&data['exif']['ImageDescription']) desc=data['exif']['ImageDescription']; } - if (desc){ + if (desc) { this.images[index].desc=desc; this.controls.show(currentImageId); this._initControlsAutoFader(); this.container.removeClass('inactive'); - }else{ + } else { this.images[index].desc=''; } } }.bind(this)); - }else if (this.images[index].desc){ + } else if (this.images[index].desc) { this.controls.show(currentImageId); this._initControlsAutoFader(); this.container.removeClass('inactive'); diff --git a/js/slideshowcontrols.js b/js/slideshowcontrols.js index 61636bcc3..42616e8e2 100644 --- a/js/slideshowcontrols.js +++ b/js/slideshowcontrols.js @@ -98,9 +98,9 @@ this._setTimeout(); } // check exif descr - if (currentImage.desc){ + if (currentImage.desc) { this._setName(currentImage.desc); - }else{ + } else { this._setName(currentImage.name); } }, diff --git a/lib/Controller/Files.php b/lib/Controller/Files.php index 4b01a52f7..e5c73f3e2 100644 --- a/lib/Controller/Files.php +++ b/lib/Controller/Files.php @@ -53,7 +53,7 @@ trait Files { * @param string $location a path picture * @return array */ - public function exif($fileId){ + public function exif($fileId) { $file = $this->downloadService->getFile($fileId); $path=$file->getInternalPath(); $storage=$file->getStorage(); @@ -64,8 +64,8 @@ public function exif($fileId){ $exif=@exif_read_data($filename); } getimagesize($filename,$blocks); - if (is_array($blocks)){ - foreach($blocks as $key => $block){ + if (is_array($blocks)) { + foreach($blocks as $key => $block) { $iptc[$key]=iptcparse($block); } } diff --git a/lib/Controller/FilesPublicController.php b/lib/Controller/FilesPublicController.php index 93e5079ec..c33ad2939 100644 --- a/lib/Controller/FilesPublicController.php +++ b/lib/Controller/FilesPublicController.php @@ -30,7 +30,7 @@ class FilesPublicController extends FilesController { * @param string $location a path picture * @return array */ - public function exif($fileId){ + public function exif($fileId) { return parent::exif($fileId); }