| 1 | # image_gps.rb $Revision: 1.7 $ |
|---|
| 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 | 2009-06-01 kp |
|---|
| 15 | * モバイルモード時も世界測地系とする |
|---|
| 16 | 2009-05-26 kp |
|---|
| 17 | * walk.eznavi.jpの場合のクエリを修正 |
|---|
| 18 | * リンク先をgoogle mapに |
|---|
| 19 | * wgs2tkyを使用しない |
|---|
| 20 | 2008-05-22 kp |
|---|
| 21 | * MapDatumがTOKYO以外の場合、WGS-84と類推する |
|---|
| 22 | 2008-01-17 kp |
|---|
| 23 | * いろいろ変更 |
|---|
| 24 | 2006-03-28 kp |
|---|
| 25 | * cooperation with ALPSLAB clip |
|---|
| 26 | 2006-03-27 kp |
|---|
| 27 | * use exifparser |
|---|
| 28 | 2005-07-25 kp |
|---|
| 29 | * correct link url when access with mobile. |
|---|
| 30 | 2005-07-19 kp |
|---|
| 31 | * MapDatum macth to WGS84 |
|---|
| 32 | 2005-05-25 kp |
|---|
| 33 | * correct url link to mapion. |
|---|
| 34 | 2005-05-24 kp |
|---|
| 35 | * create link to http://walk.eznavi.jp when access with mobile. |
|---|
| 36 | 2004-11-30 kp |
|---|
| 37 | * first version |
|---|
| 38 | =end |
|---|
| 39 | |
|---|
| 40 | require 'exifparser' |
|---|
| 41 | |
|---|
| 42 | def tky2wgs lat,lon |
|---|
| 43 | lat_w = lat - lat*0.00010695 + lon*0.000017464 + 0.0046017 |
|---|
| 44 | lon_w = lon - lat*0.000046038 - lon*0.000083043 + 0.010040 |
|---|
| 45 | lat = lat_w |
|---|
| 46 | lon = lon_w |
|---|
| 47 | return lat,lon |
|---|
| 48 | end |
|---|
| 49 | |
|---|
| 50 | def image( id, alt = 'image', thumbnail = nil, size = nil, place = 'photo' ) |
|---|
| 51 | if @conf.secure then |
|---|
| 52 | image = "#{@image_date}_#{id}.jpg" |
|---|
| 53 | image_t = "#{@image_date}_#{thumbnail}.jpg" if thumbnail |
|---|
| 54 | else |
|---|
| 55 | image = image_list( @image_date )[id.to_i] |
|---|
| 56 | image_t = image_list( @image_date )[thumbnail.to_i] if thumbnail |
|---|
| 57 | end |
|---|
| 58 | if size then |
|---|
| 59 | if size.kind_of?(Array) |
|---|
| 60 | size = " width=\"#{size[0]}\" height=\"#{size[1]}\"" |
|---|
| 61 | |
|---|
| 62 | else |
|---|
| 63 | size = " width=\"#{size.to_i}\"" |
|---|
| 64 | end |
|---|
| 65 | else |
|---|
| 66 | size = "" |
|---|
| 67 | end |
|---|
| 68 | |
|---|
| 69 | eznavi = 'http://walk.eznavi.jp' |
|---|
| 70 | google = 'http://maps.google.co.jp' |
|---|
| 71 | |
|---|
| 72 | exif = ExifParser.new("#{@image_dir}/#{image}".untaint) rescue nil |
|---|
| 73 | |
|---|
| 74 | datum = nil |
|---|
| 75 | |
|---|
| 76 | if exif |
|---|
| 77 | if @conf['image_gps.add_info'] |
|---|
| 78 | alt += ' '+exif['Model'].to_s if exif.tag?('Model') |
|---|
| 79 | alt += ' '+exif['FocalLength'].to_s if exif.tag?('FocalLength') |
|---|
| 80 | alt += ' '+exif['ExposureTime'].to_s if exif.tag?('ExposureTime') |
|---|
| 81 | alt += ' '+exif['FNumber'].to_s if exif.tag?('FNumber') |
|---|
| 82 | end |
|---|
| 83 | begin |
|---|
| 84 | lat = exif['GPSLatitude'].value |
|---|
| 85 | lat = lat[0].to_f + lat[1].to_f/60 + lat[2].to_f/3600 |
|---|
| 86 | lat = -lat if exif['GPSLatitudeRef'].value == 'S' |
|---|
| 87 | lon = exif['GPSLongitude'].value |
|---|
| 88 | lon = lon[0].to_f + lon[1].to_f/60 + lon[2].to_f/3600 |
|---|
| 89 | lon = -lon if exif['GPSLongitudeRef'].value == 'W' |
|---|
| 90 | datum = exif['GPSMapDatum'].value if exif.tag?('GPSMapDatum') |
|---|
| 91 | rescue |
|---|
| 92 | lat = nil |
|---|
| 93 | end |
|---|
| 94 | end |
|---|
| 95 | |
|---|
| 96 | unless lat.nil? |
|---|
| 97 | lat,lon = tky2wgs(lat,lon) if datum == 'TOKYO' |
|---|
| 98 | end |
|---|
| 99 | |
|---|
| 100 | if thumbnail |
|---|
| 101 | url = %Q[<a href="#{@image_url}/#{image}"><img class="#{place}" src="#{@image_url}/#{image_t}" alt="#{alt}" title="#{alt}"#{size}></a>] |
|---|
| 102 | elsif lat.nil? |
|---|
| 103 | url = %Q[<img class="#{place}" src="#{@image_url}/#{image}" alt="#{alt}" title="#{alt}"#{size}>] |
|---|
| 104 | else |
|---|
| 105 | if @conf.mobile_agent? |
|---|
| 106 | url = %Q[<a href="#{eznavi}/map?datum=0&unit=0&lat=+#{lat}&lon=+#{lon}">] |
|---|
| 107 | else |
|---|
| 108 | url = %Q[<a href="#{google}/maps?q=#{lat},#{lon}">] |
|---|
| 109 | end |
|---|
| 110 | url += %Q[<img class="#{place}" src="#{@image_url}/#{image}" alt="#{alt}" title="#{alt}" #{size}></a>] |
|---|
| 111 | end |
|---|
| 112 | url |
|---|
| 113 | end |
|---|
| 114 | |
|---|
| 115 | add_conf_proc('image_gps','image_gpsの設定','etc') do |
|---|
| 116 | if @mode == 'saveconf' then |
|---|
| 117 | @conf['image_gps.add_info'] = @cgi.params['image_gps.add_info'][0] |
|---|
| 118 | end |
|---|
| 119 | |
|---|
| 120 | <<-HTML |
|---|
| 121 | <p> |
|---|
| 122 | <h3>撮影条件の表示</h3> |
|---|
| 123 | <input type="checkbox" name="image_gps.add_info" value="true" #{if @conf['image_gps.add_info'] then " checked" end}>タイトルに撮影条件を追加する</p> |
|---|
| 124 | HTML |
|---|
| 125 | |
|---|
| 126 | end |
|---|