{"id":2601,"date":"2013-02-25T09:32:35","date_gmt":"2013-02-25T00:32:35","guid":{"rendered":"https:\/\/gunmagisgeek.com\/wordpress\/?p=2601"},"modified":"2017-02-03T01:19:29","modified_gmt":"2017-02-02T16:19:29","slug":"post-2601","status":"publish","type":"post","link":"https:\/\/gunmagisgeek.com\/blog\/node-js\/2601","title":{"rendered":"\u753b\u50cf\u304b\u3089Exif\u60c5\u5831(GPS)\u3092\u53d6\u5f97\u3059\u308b node.js or Javascript EXIF Reader"},"content":{"rendered":"<p><a href=\"http:\/\/shimz.me\/example\/getEXIF\/index.html\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/02\/streetview000003.jpg\" alt=\"streetview000003\" width=\"493\" height=\"291\" class=\"aligncenter size-full wp-image-2602\" srcset=\"https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/02\/streetview000003.jpg 493w, https:\/\/gunmagisgeek.com\/blog\/wp-content\/uploads\/2013\/02\/streetview000003-254x150.jpg 254w\" sizes=\"auto, (max-width: 493px) 100vw, 493px\" \/><\/a><\/p>\n<p>\u753b\u50cf\u304b\u3089<a href=\"http:\/\/ja.wikipedia.org\/wiki\/Exchangeable_image_file_format\">Exif<\/a>\u60c5\u5831(\u306e\u4e2d\u306e\u4f4d\u7f6e\u60c5\u5831)\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u30e1\u30e2\u3002<\/p>\n<p>&nbsp;<br \/>\n&nbsp;<\/p>\n<p><strong>\u25a0 \u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9(node.js)<\/strong><\/p>\n<p><a href=\"https:\/\/github.com\/gomfunkel\/node-exif\">node-exif<\/a>\u3068\u3044\u3046\u30e9\u30a4\u30d6\u30e9\u30ea\u304c\u3042\u3063\u305f\u306e\u3067\u4f7f\u3063\u3066\u307f\u308b\u3002<\/p>\n<pre class=\"lang:sh decode:true \" >npm install exif\r\n<\/pre>\n<pre class=\"lang:js decode:true \" title=\"getEXIF.js\" >var ExifImage = require('exif').ExifImage;\r\n\r\ntry {\r\n    new ExifImage({ image : 'test.jpg' }, function (error, image) {\r\n        if (error)\r\n            console.log('Error: '+error.message);\r\n        else\r\n            console.dir(image['gps']);\r\n    });\r\n} catch (error) {\r\n    console.log('Error: ' + error);\r\n}<\/pre>\n<pre class=\"lang:sh decode:true \" title=\"\u5b9f\u884c\" >$ node getEXIF.js\r\n<\/pre>\n<p>Exif\u60c5\u5831\u306f\u53d6\u5f97\u3067\u304d\u308b\u304c\u3001\u306a\u305c\u304b\u6b63\u3057\u3044\u4f4d\u7f6e\u60c5\u5831\u304c\u53d6\u5f97\u3067\u304d\u306a\u3044\u3002<\/p>\n<pre class=\"lang:js mark:10,20 decode:true \" title=\"\u51fa\u529b\u7d50\u679c\" >gps:[\r\n  { tag: &lt;Buffer 00 01&gt;,\r\n    format: 2,\r\n    components: 2,\r\n    value: 'N',\r\n    tagName: 'GPSLatitudeRef' },\r\n  { tag: &lt;Buffer 00 02&gt;,\r\n    format: 5,\r\n    components: 3,\r\n    value: [ 36, 36, 36 ],\r\n    tagName: 'GPSLatitude' },\r\n  { tag: &lt;Buffer 00 03&gt;,\r\n    format: 2,\r\n    components: 2,\r\n    value: 'E',\r\n    tagName: 'GPSLongitudeRef' },\r\n  { tag: &lt;Buffer 00 04&gt;,\r\n    format: 5,\r\n    components: 3,\r\n    value: [ 139, 139, 139 ],\r\n    tagName: 'GPSLongitude' },\r\n  { tag: &lt;Buffer 00 07&gt;,\r\n    format: 5,\r\n    components: 3,\r\n    value: [ 11, 11, 11 ],\r\n    tagName: 'GPSTimeStamp' }\r\n]\r\n<\/pre>\n<p>\u3057\u304b\u305f\u304c\u306a\u3044\u306e\u3067\u3001imagemagick\u306ewrapper(<a href=\"https:\/\/github.com\/rsms\/node-imagemagick\">node-imagemagick<\/a>)\u3092\u4f7f\u3046\u3002<br \/>\n\u975e\u540c\u671f\u306e\u30d5\u30ed\u30fc\u5236\u5fa1\u306b<a href=\"https:\/\/github.com\/caolan\/async\">async<\/a>\u3092\u4f7f\u3046\u306e\u3067\u3001\u4e00\u7dd2\u306b\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u3002<\/p>\n<pre class=\"lang:sh decode:true \" >$ yum install ImageMagick\r\n$ npm install imagemagick\r\n$ npm install async\r\n<\/pre>\n<pre class=\"lang:js decode:true \" title=\"getEXIF2.js\" >var im = require('imagemagick');\r\nvar async = require('async');\r\n \r\n var imgFile = 'test.jpg';\r\n \r\n async.series(\r\n [\r\n\t function(callback) { im.identify(['-format', '%[EXIF:GPSLatitude]', imgFile],\r\n\t\t function(err, metadata){ \r\n\t\t\tif (err) callback(err);\r\n\t\t\tcallback(null, { 'GPSLatitude': metadata.trimRight() });\r\n\t\t });\r\n\t }, function(callback) { im.identify(['-format', '%[EXIF:GPSLatitudeRef]', imgFile],\r\n\t\t function(err, metadata){ \r\n\t\t\tif (err) callback(err);\r\n\t\t\tcallback(null, { 'GPSLatitudeRef': metadata.trimRight() });\r\n\t\t });\r\n\t }, function(callback) { im.identify(['-format', '%[EXIF:GPSLongitude]', imgFile],\r\n\t\t function(err, metadata){ \r\n\t\t\tif (err) callback(err);\r\n\t\t\tcallback(null, { 'GPSLongitude': metadata.trimRight() });\r\n\t\t });\r\n\t }, function(callback) { im.identify(['-format', '%[EXIF:GPSLongitudeRef]', imgFile ],\r\n\t\t function(err, metadata){ \r\n\t\t\tif (err) callback(err);\r\n\t\t\tcallback(null, { 'GPSLongitudeRef': metadata.trimRight() });\r\n\t\t });\r\n\t }\r\n ],\r\n function(err, results){\r\n    console.dir(results);\r\n});<\/pre>\n<pre class=\"lang:sh decode:true \" title=\"\u5b9f\u884c\" >$ node getECIF2.js<\/pre>\n<p>\u6b63\u3057\u304f\u3001\u4f4d\u7f6e\u60c5\u5831\u304c\u53d6\u5f97\u3067\u304d\u305f\u3002<\/p>\n<pre class=\"lang:js decode:true \" title=\"\u51fa\u529b\u7d50\u679c\" >[\r\n  { GPSLatitude: '36\/1, 1968\/100, 0\/1' },\r\n  { GPSLatitudeRef: 'N' },\r\n  { GPSLongitude: '139\/1, 49\/100, 0\/1' },\r\n  { GPSLongitudeRef: 'E' }\r\n]\r\n<\/pre>\n<p>&nbsp;<br \/>\n&nbsp;<\/p>\n<p><strong>\u25a0 \u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u30b5\u30a4\u30c9<\/strong><br \/>\n\u4e0b\u8a18\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u4f7f\u7528\u3059\u308b\uff08\u4eca\u56de\u306fjQuery\u7248\u3092\u4f7f\u7528\uff09<br \/>\n<span class=\"removed_link\" title=\"http:\/\/www.nihilogic.dk\/labs\/exif\/\">Javascript EXIF Reader<\/span><br \/>\n<span class=\"removed_link\" title=\"http:\/\/www.nihilogic.dk\/labs\/exifjquery\/\">Javascript EXIF Reader &#8211; jQuery Plugin<\/span><br \/>\n\u4f7f\u7528\u6cd5\u306f\u3044\u305f\u3063\u3066\u7c21\u5358\u3002<br \/>\n\u30e9\u30a4\u30d6\u30e9\u30ea\u3092\u8aad\u307f\u8fbc\u3093\u3067jQuery\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30e1\u30bd\u30c3\u30c9\u3068\u3057\u3066\u300c.exif()\u300d\u3092\u4f7f\u7528\u3059\u308b\u3060\u3051\u3002<\/p>\n<pre class=\"lang:xhtml mark:7,18,19 decode:true \" >&lt;!DOCTYPE html&gt;\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n&lt;meta charset=&quot;utf-8&quot; \/&gt;\r\n\r\n&lt;script type=&quot;text\/javascript&quot; src=&quot;http:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/1.7.2\/jquery.min.js&quot;&gt;&lt;\/script&gt;\r\n&lt;script src=&quot;jquery.exif.js&quot;&gt;&lt;\/script&gt;\r\n&lt;title&gt;Javascript EXIF Reader text&lt;\/title&gt;\r\n\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;a href=&quot;http:\/\/www.nihilogic.dk\/labs\/exif\/&quot;&gt;Javascript EXIF Reader&lt;\/a&gt; \u30c6\u30b9\u30c8(\u30af\u30ea\u30c3\u30af\u3067\u4f4d\u7f6e\u60c5\u5831\u8868\u793a)\r\n&lt;img src=&quot;test.jpg&quot; id=&quot;img&quot; exif=&quot;true&quot; \/&gt;\r\n\r\n&lt;script&gt;\r\n$(&quot;#img&quot;).click(function() {\r\n\talert(\r\n\t      &quot;Longitude: &quot; + $(this).exif(&quot;GPSLongitude&quot;) + &quot;n&quot; +\r\n\t      &quot;Latitude: &quot; + $(this).exif(&quot;GPSLatitude&quot;)\r\n\t      );\r\n});\r\n&lt;\/script&gt;\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;<\/pre>\n<p><a href=\"http:\/\/shimz.me\/example\/getEXIF\/index.html\">example<\/a><\/p>\n<p>\u305f\u3060\u3001\u300cinput type=&#8217;file&#8217;\u300d\u3067\u9078\u629e\u3057\u305f\u753b\u50cf\u304b\u3089\u4e0a\u8a18\u30e9\u30a4\u30d6\u30e9\u30ea\u3067Exif\u60c5\u5831\u3092\u53d6\u5f97\u3059\u308b\u65b9\u6cd5\u304c\u308f\u304b\u3089\u306a\u3044\uff08\u3067\u304d\u306a\u3044\uff1f\uff09<br \/>\ndata URI scheme\u306b\u3057\u3066\u3057\u307e\u3046\u3068Exif\u60c5\u5831\u306f\u53d6\u5f97\u3067\u304d\u306a\u3044\u307f\u305f\u3044\u3002<br \/>\n\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u3067\u5b8c\u7d50\u3067\u304d\u306a\u3044\u307f\u305f\u3044\u306a\u306e\u3067\u3001\u7d50\u5c40\u30b5\u30fc\u30d0\u30fc\u5074\u306b\u753b\u50cf\u3092\u4e00\u65e6\u4fdd\u5b58\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u3063\u307d\u3044\u3002<\/p>\n<pre class=\"lang:js decode:true \" title=\"\u5931\u6557\u4f8b\" >\/\/\u3053\u306e\u30b3\u30fc\u30c9\u306f\u52d5\u304b\u306a\u3044\r\n$(&quot;#uploadFile&quot;).change(function() {\r\n\r\n    var file = this.files[0]; \/\/input type=&quot;file&quot;\u304b\u3089\u30d5\u30a1\u30a4\u30eb\u3092\u53d6\u5f97\r\n    if (!file.type.match(\/^image\/(png|jpeg|gif)$\/)) return;\r\n\r\n    var reader = new FileReader();\r\n    reader.readAsDataURL(file); \/\/data URI scheme\u3068\u3057\u3066\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307f\r\n    reader.onload = function(evt) {\r\n\t    $(&quot;#img&quot;).attr(&quot;src&quot;, evt.target.result); \/\/\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u3092img\u30bf\u30b0\u306esrc\u306b\u8ffd\u52a0\r\n    }\r\n    \r\n    \/\/img\u30bf\u30b0\u306esrc\u306b\u6307\u5b9a\u3055\u308c\u3066\u3044\u308b\u306e\u304cdata URI scheme\u3060\u3068Exif\u304c\u53d6\u5f97\u3067\u304d\u306a\u3044\r\n   $(&quot;#img&quot;).click(function() { \r\n    alert(\r\n\t  &quot;Longitude: &quot; + $(this).exif(&quot;GPSLongitude&quot;) + &quot;n&quot; +\r\n\t  &quot;Latitude: &quot; + $(this).exif(&quot;GPSLatitude&quot;)\r\n\t  );\r\n    });        \r\n});\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u753b\u50cf\u304b\u3089Exif\u60c5\u5831(\u306e\u4e2d\u306e\u4f4d\u7f6e\u60c5\u5831)\u3092\u53d6\u5f97\u3059\u308b\u65b9&hellip;<\/p>\n","protected":false},"author":1,"featured_media":2602,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,5],"tags":[],"class_list":["post-2601","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","category-node-js","has-post-thumbnail-archive"],"_links":{"self":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2601","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/comments?post=2601"}],"version-history":[{"count":1,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2601\/revisions"}],"predecessor-version":[{"id":2603,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/posts\/2601\/revisions\/2603"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media\/2602"}],"wp:attachment":[{"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/media?parent=2601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/categories?post=2601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gunmagisgeek.com\/blog\/wp-json\/wp\/v2\/tags?post=2601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}