| 1 | # image_gps.rb $Revision: 1.6 $ |
|---|
| 2 | # |
|---|
| 3 | # 概要: |
|---|
| 4 | # 画像にGPSによる位置情報が含まれている場合は、対応する地図へのリンクを生成する。 |
|---|
| 5 | # |
|---|
| 6 | # 使い方: |
|---|
| 7 | # 絵日記Plugin(image.rb)とおなじ |
|---|
| 8 | # |
|---|
| 9 | # Copyright (c) 2004,2005 kp <kp@mmho.no-ip.org> |
|---|
| 10 | # Distributed under the GPL |
|---|
| 11 | # |
|---|
| 12 | |
|---|
| 13 | =begin ChangeLog |
|---|
| 14 | 2008-05-22 kp |
|---|
| 15 | * MapDatumがTOKYO以外の場合、WGS-84と類推する |
|---|
| 16 | 2008-01-17 kp |
|---|
| 17 | * いろいろ変更 |
|---|
| 18 | 2006-03-28 kp |
|---|
| 19 | * cooperation with ALPSLAB clip |
|---|
| 20 | 2006-03-27 kp |
|---|
| 21 | * use exifparser |
|---|
| 22 | 2005-07-25 kp |
|---|
| 23 | * correct link url when access with mobile. |
|---|
| 24 | 2005-07-19 kp |
|---|
| 25 | * MapDatum macth to WGS84 |
|---|
| 26 | 2005-05-25 kp |
|---|
| 27 | * correct url link to mapion. |
|---|
| 28 | 2005-05-24 kp |
|---|
| 29 | * create link to http://walk.eznavi.jp when access with mobile. |
|---|
| 30 | 2004-11-30 kp |
|---|
| 31 | * first version |
|---|
| 32 | =end |
|---|
| 33 | |
|---|
| 34 | require 'wgs2tky' |
|---|
| 35 | require 'exifparser' |
|---|
| 36 | |
|---|
| 37 | def image( id, alt = 'image', thumbnail = nil, size = nil, place = 'photo' ) |
|---|
| 38 | if @conf.secure then |
|---|
| 39 | image = "#{@image_date}_#{id}.jpg" |
|---|
| 40 | image_t = "#{@image_date}_#{thumbnail}.jpg" if thumbnail |
|---|
| 41 | else |
|---|
| 42 | image = image_list( @image_date )[id.to_i] |
|---|
| 43 | image_t = image_list( @image_date )[thumbnail.to_i] if thumbnail |
|---|
| 44 | end |
|---|
| 45 | if size then |
|---|
| 46 | if size.kind_of?(Array) |
|---|
| 47 | size = " width=\"#{size[0]}\" height=\"#{size[1]}\"" |
|---|
| 48 | |
|---|
| 49 | else |
|---|
| 50 | size = " width=\"#{size.to_i}\"" |
|---|
| 51 | end |
|---|
| 52 | else |
|---|
| 53 | size = "" |
|---|
| 54 | end |
|---|
| 55 | |
|---|
| 56 | eznavi = 'http://walk.eznavi.jp' |
|---|
| 57 | mapion = 'http://www.mapion.co.jp' |
|---|
| 58 | |
|---|
| 59 | exif = ExifParser.new("#{@image_dir}/#{image}".untaint) rescue nil |
|---|
| 60 | |
|---|
| 61 | el = nil |
|---|
| 62 | nl = nil |
|---|
| 63 | datum = nil |
|---|
| 64 | |
|---|
| 65 | if exif |
|---|
| 66 | if @conf['image_gps.add_info'] |
|---|
| 67 | alt += ' '+exif['Model'].to_s if exif.tag?('Model') |
|---|
| 68 | alt += ' '+exif['FocalLength'].to_s if exif.tag?('FocalLength') |
|---|
| 69 | alt += ' '+exif['ExposureTime'].to_s if exif.tag?('ExposureTime') |
|---|
| 70 | alt += ' '+exif['FNumber'].to_s if exif.tag?('FNumber') |
|---|
| 71 | end |
|---|
| 72 | begin |
|---|
| 73 | if(exif['GPSLatitudeRef'].value == 'N' && exif['GPSLongitudeRef'].value == 'E') |
|---|
| 74 | nl = exif['GPSLatitude'].value if exif.tag?('GPSLatitude') |
|---|
| 75 | el = exif['GPSLongitude'].value if exif.tag?('GPSLongitude') |
|---|
| 76 | datum = exif['GPSMapDatum'].value if exif.tag?('GPSMapDatum') |
|---|
| 77 | end |
|---|
| 78 | rescue |
|---|
| 79 | end |
|---|
| 80 | end |
|---|
| 81 | |
|---|
| 82 | unless el.nil? |
|---|
| 83 | if @conf.mobile_agent? |
|---|
| 84 | lat = "#{sprintf("%d.%d.%.2f",*nl)}" |
|---|
| 85 | lon = "#{sprintf("%d.%d.%.2f",*el)}" |
|---|
| 86 | else |
|---|
| 87 | Wgs2Tky.conv!(nl,el) unless datum == /TOKYO/ |
|---|
| 88 | lat ="#{sprintf("%d/%d/%.3f",*nl)}" |
|---|
| 89 | lon ="#{sprintf("%d/%d/%.3f",*el)}" |
|---|
| 90 | end |
|---|
| 91 | end |
|---|
| 92 | |
|---|
| 93 | if thumbnail |
|---|
| 94 | url = %Q[<a href="#{@image_url}/#{image}"><img class="#{place}" src="#{@image_url}/#{image_t}" alt="#{alt}" title="#{alt}"#{size}></a>] |
|---|
| 95 | elsif el.nil? |
|---|
| 96 | url = %Q[<img class="#{place}" src="#{@image_url}/#{image}" alt="#{alt}" title="#{alt}"#{size}>] |
|---|
| 97 | else |
|---|
| 98 | if @conf.mobile_agent? |
|---|
| 99 | url = %Q[<a href="#{eznavi}/map?datum=#{datum=='TOKYO'?'1':'0'}&unit=0&lat=+#{lat}&lon=+#{lon}">] |
|---|
| 100 | else |
|---|
| 101 | url = %Q[<a href="#{mapion}/c/f?el=#{lon}&nl=#{lat}&uc=1&grp=all">] |
|---|
| 102 | end |
|---|
| 103 | url += %Q[<img class="#{place}" src="#{@image_url}/#{image}" alt="#{alt}" title="#{alt}" #{size}></a>] |
|---|
| 104 | end |
|---|
| 105 | url |
|---|
| 106 | end |
|---|
| 107 | |
|---|
| 108 | add_conf_proc('image_gps','image_gpsの設定','etc') do |
|---|
| 109 | if @mode == 'saveconf' then |
|---|
| 110 | @conf['image_gps.add_info'] = @cgi.params['image_gps.add_info'][0] |
|---|
| 111 | end |
|---|
| 112 | |
|---|
| 113 | <<-HTML |
|---|
| 114 | <p> |
|---|
| 115 | <h3>撮影条件の表示</h3> |
|---|
| 116 | <input type="checkbox" name="image_gps.add_info" value="true" #{if @conf['image_gps.add_info'] then " checked" end}>タイトルに撮影条件を追加する</p> |
|---|
| 117 | HTML |
|---|
| 118 | |
|---|
| 119 | end |
|---|