| 1 | # image_gps.rb $Revision: 0.8 $ |
|---|
| 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 | * first version |
|---|
| 16 | * fork from image_gps.rb |
|---|
| 17 | =end |
|---|
| 18 | |
|---|
| 19 | require 'exifparser' |
|---|
| 20 | |
|---|
| 21 | def tky2wgs lat,lon |
|---|
| 22 | lat_w = lat - lat*0.00010695 + lon*0.000017464 + 0.0046017 |
|---|
| 23 | lon_w = lon - lat*0.000046038 - lon*0.000083043 + 0.010040 |
|---|
| 24 | lat = lat_w |
|---|
| 25 | lon = lon_w |
|---|
| 26 | return lat,lon |
|---|
| 27 | end |
|---|
| 28 | |
|---|
| 29 | def image( id, alt = 'image', thumbnail = nil, size = nil, place = 'photo' ) |
|---|
| 30 | if @conf.secure then |
|---|
| 31 | image = "#{@image_date}_#{id}.jpg" |
|---|
| 32 | image_t = "#{@image_date}_#{thumbnail}.jpg" if thumbnail |
|---|
| 33 | else |
|---|
| 34 | image = image_list( @image_date )[id.to_i] |
|---|
| 35 | image_t = image_list( @image_date )[thumbnail.to_i] if thumbnail |
|---|
| 36 | end |
|---|
| 37 | if size then |
|---|
| 38 | if size.kind_of?(Array) |
|---|
| 39 | size = " width=\"#{size[0]}\" height=\"#{size[1]}\"" |
|---|
| 40 | |
|---|
| 41 | else |
|---|
| 42 | size = " width=\"#{size.to_i}\"" |
|---|
| 43 | end |
|---|
| 44 | else |
|---|
| 45 | size = "" |
|---|
| 46 | end |
|---|
| 47 | |
|---|
| 48 | exif = ExifParser.new("#{@image_dir}/#{image}".untaint) rescue nil |
|---|
| 49 | |
|---|
| 50 | datum = nil |
|---|
| 51 | |
|---|
| 52 | if exif |
|---|
| 53 | if @conf['image_gps.add_info'] |
|---|
| 54 | alt += ' '+exif['Model'].to_s if exif.tag?('Model') |
|---|
| 55 | alt += ' '+exif['FocalLength'].to_s if exif.tag?('FocalLength') |
|---|
| 56 | alt += ' '+exif['ExposureTime'].to_s if exif.tag?('ExposureTime') |
|---|
| 57 | alt += ' '+exif['FNumber'].to_s if exif.tag?('FNumber') |
|---|
| 58 | end |
|---|
| 59 | begin |
|---|
| 60 | lat = exif['GPSLatitude'].value |
|---|
| 61 | lat = lat[0].to_f + lat[1].to_f/60 + lat[2].to_f/3600 |
|---|
| 62 | lat = -lat if exif['GPSLatitudeRef'].value == 'S' |
|---|
| 63 | lon = exif['GPSLongitude'].value |
|---|
| 64 | lon = lon[0].to_f + lon[1].to_f/60 + lon[2].to_f/3600 |
|---|
| 65 | lon = -lon if exif['GPSLongitudeRef'].value == 'W' |
|---|
| 66 | datum = exif['GPSMapDatum'].value if exif.tag?('GPSMapDatum') |
|---|
| 67 | rescue |
|---|
| 68 | lat = nil |
|---|
| 69 | end |
|---|
| 70 | end |
|---|
| 71 | |
|---|
| 72 | unless lat.nil? |
|---|
| 73 | lat,lon = tky2wgs(lat,lon) if datum == 'TOKYO' |
|---|
| 74 | end |
|---|
| 75 | |
|---|
| 76 | img = %Q[<img class="#{place}" src="#{@image_url}/#{image}" alt="#{alt}" title="#{alt}" #{size}>] |
|---|
| 77 | img_t = %Q[<img class="#{place}" src="#{@image_url}/#{image_t}" alt="#{alt}" title="#{alt}" #{size}>] |
|---|
| 78 | |
|---|
| 79 | #static map |
|---|
| 80 | unless lat.nil? |
|---|
| 81 | img_map = %Q["http://maps.google.com/staticmap?format=gif&] |
|---|
| 82 | img_map += %Q[center=#{lat},#{lon}&zoom=14&size=200x200&markers=#{lat},#{lon}&] |
|---|
| 83 | img_map += %Q[key=#{@conf['image_gps.google_maps_api_key']}&sensor=false"] |
|---|
| 84 | else |
|---|
| 85 | img_map = '' |
|---|
| 86 | end |
|---|
| 87 | |
|---|
| 88 | url = '' |
|---|
| 89 | if @conf.mobile_agent? |
|---|
| 90 | url += %Q[<a href=#{img_map}>] unless lat.nil? |
|---|
| 91 | url += thumbnail ? img_t : img |
|---|
| 92 | url += %Q[</a>] unless lat.nil? |
|---|
| 93 | else |
|---|
| 94 | url += %Q[<a href="#{@image_url}/#{image}">] |
|---|
| 95 | url += thumbnail ? img_t : img |
|---|
| 96 | url += %Q[<img class="map" src=#{img_map} border="0">] unless lat.nil? |
|---|
| 97 | url +=%Q[</a>] |
|---|
| 98 | end |
|---|
| 99 | url |
|---|
| 100 | end |
|---|
| 101 | |
|---|
| 102 | add_header_proc do |
|---|
| 103 | if @mode !~ /conf$/ and not bot? then |
|---|
| 104 | <<-HTML |
|---|
| 105 | <style type="text/css"><!-- |
|---|
| 106 | img.map{ |
|---|
| 107 | position:fixed; |
|---|
| 108 | top:30px; |
|---|
| 109 | left:30px; |
|---|
| 110 | display:none; |
|---|
| 111 | outline:5px; |
|---|
| 112 | outline-style:solid; |
|---|
| 113 | outline-color:gray; |
|---|
| 114 | } |
|---|
| 115 | a:hover{ |
|---|
| 116 | position:relative; |
|---|
| 117 | } |
|---|
| 118 | a:hover img.map{ |
|---|
| 119 | display:block; |
|---|
| 120 | } |
|---|
| 121 | --></style> |
|---|
| 122 | HTML |
|---|
| 123 | else |
|---|
| 124 | '' |
|---|
| 125 | end |
|---|
| 126 | end |
|---|
| 127 | |
|---|
| 128 | add_conf_proc('image_gps','image_gpsの設定','etc') do |
|---|
| 129 | if @mode == 'saveconf' then |
|---|
| 130 | @conf['image_gps.add_info'] = @cgi.params['image_gps.add_info'][0] |
|---|
| 131 | @conf['image_gps.google_maps_api_key'] = @cgi.params['image_gps.google_maps_api_key'][0] |
|---|
| 132 | end |
|---|
| 133 | |
|---|
| 134 | <<-HTML |
|---|
| 135 | <p> |
|---|
| 136 | <h3>撮影条件の表示</h3> |
|---|
| 137 | <input type="checkbox" name="image_gps.add_info" value="true" #{if @conf['image_gps.add_info'] then " checked" end}>タイトルに撮影条件を追加する |
|---|
| 138 | <h3>Google Maps API Key</h3> |
|---|
| 139 | <input type="text" name="image_gps.google_maps_api_key" value="#{@conf['image_gps.google_maps_api_key']}"> |
|---|
| 140 | </p> |
|---|
| 141 | HTML |
|---|
| 142 | |
|---|
| 143 | end |
|---|