summaryrefslogtreecommitdiffstats
path: root/sci-geosciences/happycamel/files/happycamel-v1-beta3-ds-features.patch
blob: 4bf9abccd80dfd6e05fb4edf185573464e73a040 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
diff -dPNur happycamel-v1-beta3/HappyCamel/cli.py happycamel-v1-beta3-ds/HappyCamel/cli.py
--- happycamel-v1-beta3/HappyCamel/cli.py	2008-04-17 21:25:10.000000000 +0200
+++ happycamel-v1-beta3-ds/HappyCamel/cli.py	2008-11-19 13:58:07.000000000 +0100
@@ -221,11 +221,16 @@
       parser.addOption("--image-size", metavar = "pixels", var = "image_size",
                        type = "int", default = defaults["image_size"],
                        help = "The size of the long side of the photo in the KMZ file. Currently set to %default.")
+      parser.addOption("--icon-size", metavar = "pixels", var = "icon_size",
+                       type = "int", default = defaults["icon_size"],
+                       help = "The size of the long side of the icon in the KMZ file. Currently set to %default.")
       parser.addOption("--title", metavar = "title", var = "title",
                        default = defaults["title"], help = "The title of your KMZ file. Currently set to \"%default\".")
       parser.addOption("--clickable", var = "clickable", type = "bool",
                        bool_action = True, default = defaults["clickable"],
                        help = "It true, make the images clickable so they are shown in your web browser. WARNING: When using disk photos, this is not portable across computers, unless the photo's are placed at exactly the same path as on the original machine. Currently set to %default.")                      
+      parser.addOption("--url", var = "url",
+                       default = "", help = "Defines URL there the photos are published. Currently set to %default.")
       parser.addOption("--track", type = "bool", bool_action = True,
                        var = "show_track", default = defaults["show_track"],
                        help = "Show the GPS track in the KMZ file. Currently set to %default.")
@@ -315,8 +320,10 @@
       options["kmz_file"]       = False
       options["order"]          = False
       options["image_size"]     = False
+      options["icon_size"]      = False
       options["title"]          = False
       options["clickable"]      = False
+      options["url"]            = False
       options["show_track"]     = False
       options["track_color"]    = False
       options["track_width"]    = False
diff -dPNur happycamel-v1-beta3/HappyCamel/config.py happycamel-v1-beta3-ds/HappyCamel/config.py
--- happycamel-v1-beta3/HappyCamel/config.py	2008-04-17 21:25:10.000000000 +0200
+++ happycamel-v1-beta3-ds/HappyCamel/config.py	2008-11-19 13:54:41.000000000 +0100
@@ -78,8 +78,10 @@
     "show_waypoints":      [bool,  "KMZ File", "Show waypoints", False],
     "order":               [str,   "KMZ File", "Order", "D"],
     "image_size":          [int,   "KMZ File", "Pixels", 200],
+    "icon_size":           [int,   "KMZ File", "Icon pixels", 0],
     "title":               [str,   "KMZ File", "Title", "Photo report"],
-    "clickable":           [bool,  "KMZ File", "Clickable", False]
+    "clickable":           [bool,  "KMZ File", "Clickable", False],
+    "url":                 [str,   "KMZ File", "Photos URL", ""]
   }
     
   def __init__(self):
@@ -133,7 +135,7 @@
       if (type(value) == self.map[option][0]):
         self.values[option] = value
       else:
-        raise TypeError, "Expected %s, but got %s instead" % (self.map[options][0], type(value))
+        raise TypeError, "Expected %s, but got %s instead for option %s" % (self.map[option][0], type(value), option)
     else:
       raise UnknownOptionError(option)
 
diff -dPNur happycamel-v1-beta3/HappyCamel/kmlhandler.py happycamel-v1-beta3-ds/HappyCamel/kmlhandler.py
--- happycamel-v1-beta3/HappyCamel/kmlhandler.py	2008-04-17 21:25:10.000000000 +0200
+++ happycamel-v1-beta3-ds/HappyCamel/kmlhandler.py	2008-11-19 13:57:31.000000000 +0100
@@ -27,7 +27,7 @@
   def __init__(self, gpx_files, photo_list, thumbnail_names, logger,
                title = "Photo report", track_color = "ffffffff",
                track_width = 1.0,  between_tracks_color = None,
-               between_tracks_width = None, photos_clickable = False):
+               between_tracks_width = None, photos_clickable = False, photos_url = "", use_icons = False):
     """ Initialize a new KML file. gpx_files is a list of GPXFile objects which
         should be drawn in the file. photo_list is a PhotoList object of
         photo's whose thumbnail should be included. thumbnail_names is an
@@ -43,6 +43,8 @@
     self.thumbnail_names  = thumbnail_names
     self.title            = title
     self.photos_clickable = photos_clickable
+    self.photos_url       = photos_url
+    self.use_icons        = use_icons
 
     # Check if the specified track colors and widths are ok
     self.track_color          = self.__testColorFormat__(track_color)
@@ -117,11 +119,28 @@
     for photo in self.photo_list:
       if (photo in self.thumbnail_names): # Only process if there's a thumbnail
         location = photo.getLocation()
+
+	if (self.use_icons):
+	  out_fp.write('  <Style id="photo_%s">\n' % self.thumbnail_names[photo])
+	  out_fp.write('    <IconStyle>\n')
+	  out_fp.write('      <scale>1.5</scale>\n')
+	  out_fp.write('      <Icon>\n')
+	  out_fp.write('        <href>icons/%s</href>\n' % self.thumbnail_names[photo])
+	  out_fp.write('      </Icon>\n')
+	  out_fp.write('    </IconStyle>\n')
+	  out_fp.write('    <LabelStyle>\n')
+	  out_fp.write('      <scale>0.2</scale>\n')
+	  out_fp.write('    </LabelStyle>\n')
+	  out_fp.write('  </Style>\n')
+
         out_fp.write('  <Placemark>\n')
         out_fp.write('    <name>%s</name>\n' % photo.getName())
         out_fp.write('    <description><![CDATA[')
         if (self.photos_clickable):
-          out_fp.write('<a href="%s">' % photo.getURL())
+	  if (self.photos_url):
+            out_fp.write('<a href="%s/%s">' % (self.photos_url, photo.getName()))
+	  else:
+            out_fp.write('<a href="%s">' % photo.getURL())
         out_fp.write('<img src="images/%s" />' % self.thumbnail_names[photo])
         if (self.photos_clickable):
           out_fp.write("</a>")
@@ -136,7 +155,11 @@
             out_fp.write('    <Snippet><![CDATA[%s]]></Snippet>\n' % comment)
         else:
           out_fp.write('    <Snippet>%s</Snippet>\n' % photo.getName())
-        out_fp.write('    <styleUrl>#photo_mark</styleUrl>\n')
+
+	if (self.use_icons):
+	  out_fp.write('      <styleUrl>#photo_%s</styleUrl>\n' % self.thumbnail_names[photo])
+	else:
+	  out_fp.write('    <styleUrl>#photo_mark</styleUrl>\n')
         out_fp.write('    <Point>\n')
         if (location[2]):
           out_fp.write('      <altitudeMode>clampToGround</altitudeMode>\n')
@@ -275,10 +298,10 @@
   NUM_THUMBNAILS = 25
 
   def __init__(self, file_name, logger, gpx_files = None, photo_list = None,
-               sort_order = "D", thumbnail_size = 200, title = "Photo report",
+               sort_order = "D", thumbnail_size = 200, icon_size = 0, title = "Photo report",
                track_color = "ffffffff", track_width = 1.0,
                between_tracks_color = None, between_tracks_width = None,
-               photos_clickable = False):
+               photos_clickable = False, photos_url = ""):
     """ Create a new KMZ file with the disk path file_name. gpx_files is a list
         of GPXFile objects that need to be showed in the file. photo_list is a
         PhotoList object of photo's whose thumbnail should be included.
@@ -286,8 +309,9 @@
         presented ("D" is date and time, "A" is latitude, "O" is longitude.
         Lowercase means reverse sort. Multiple tokens may be specified in order
         of precedence).
-        thumbnail_size is the number of pixels the long size of each thumbnail
-        should have.
+        thumbnail_size is the number of pixels the long size of each thumbnail 
+	should have.
+	icon_size is the number of pixels the long size of each icon should have.
         title is the title given to the report in Google Earth.
         track_color and between_tracks_color specify the color to give the
         tracks and the lines in between the tracks, respectively. They are
@@ -309,12 +333,14 @@
     self.gpx_files            = gpx_files
     self.photo_list           = photo_list
     self.thumbnail_size       = thumbnail_size
+    self.icon_size            = icon_size
     self.title                = title
     self.track_width          = track_width
     self.track_color          = track_color
     self.between_tracks_width = between_tracks_width
     self.between_tracks_color = between_tracks_color
     self.photos_clickable     = photos_clickable
+    self.photos_url           = photos_url
 
     # Sort the photo's
     for index in range(len(sort_order)):
@@ -366,7 +392,9 @@
         file_names[photo] = "%s.jpg" % fn_base
         
         # Write the file
-        zip_file.writestr("images/%s.jpg" % fn_base, data)
+        zip_file.writestr("images/%s.jpg" % fn_base, data[0])
+	if (data[1]):
+	    zip_file.writestr("icons/%s.jpg" % fn_base, data[1])
       else:
         self.logger.error("Couldn't make a thumbnail of image %s." % photo.getName())
         
@@ -391,7 +419,7 @@
       # but we put it here in a separate thread here as well because at the same
       # time we need to start the processing thread.
       get_thread = threading.Thread(target = self.photo_list.getThumbnailData,
-                                    args = [self.thumbnail_size, tn_queue])
+                                    args = [self.thumbnail_size, self.icon_size, tn_queue])
       file_names = {}
       process_thread = threading.Thread(target = self.__processThumbnails__,
                                         args = [tn_queue, out_file, file_names])
@@ -410,7 +438,7 @@
     kml = KML(self.gpx_files, self.photo_list, file_names, self.logger,
               self.title, self.track_color, self.track_width,
               self.between_tracks_color, self.between_tracks_width,
-              self.photos_clickable)
+              self.photos_clickable, self.photos_url, bool(self.icon_size))
     kml_fp = StringIO.StringIO()
     kml.writeKML(kml_fp, write_photos, write_waypoints, write_track, write_between_tracks)
 
diff -dPNur happycamel-v1-beta3/HappyCamel/main.py happycamel-v1-beta3-ds/HappyCamel/main.py
--- happycamel-v1-beta3/HappyCamel/main.py	2008-04-17 21:25:10.000000000 +0200
+++ happycamel-v1-beta3-ds/HappyCamel/main.py	2008-11-19 14:22:55.000000000 +0100
@@ -254,12 +254,14 @@
         self.writeKMZFile(self.geo_sources.getAllGPXFiles(), photo_list,
                           kmz_file, self.conf.get("order"),
                           self.conf.get("image_size"),
+                          self.conf.get("icon_size"),
                           self.conf.get("title"),
                           self.conf.get("track_color"),
                           self.conf.get("track_width"),
                           self.conf.get("between_color"),
                           self.conf.get("between_width"),
                           self.conf.get("clickable"),
+			  self.conf.get("url"),
                           self.conf.get("show_waypoints"),
                           self.conf.get("show_track"),
                           self.conf.get("show_between_tracks"))
@@ -525,16 +527,16 @@
       if not (results[photo]):
         self.logger.message("Couldn't succesfully write metadata to photo %s." % photo.getName())
 
-  def writeKMZFile(self, gpx_files, photo_list, file_path, order, image_size,
+  def writeKMZFile(self, gpx_files, photo_list, file_path, order, image_size, icon_size,
                    title, track_color, track_width, between_color,
-                   between_width, clickable, show_waypoints, show_track,
+                   between_width, clickable, photos_url, show_waypoints, show_track,
                    show_between_tracks):
 
     """ Write the KMZ file with the specified options. """
 
     kmz = kmlhandler.KMZ(file_path, self.logger, gpx_files,
-                         photo_list, order, image_size, title, track_color,
-                         track_width, between_color, between_width, clickable)
+                         photo_list, order, image_size, icon_size, title, track_color,
+                         track_width, between_color, between_width, clickable, photos_url)
 
     kmz.writeFile(write_photos = True,
                   write_waypoints = show_waypoints, write_track = show_track,
diff -dPNur happycamel-v1-beta3/HappyCamel/photohandler.py happycamel-v1-beta3-ds/HappyCamel/photohandler.py
--- happycamel-v1-beta3/HappyCamel/photohandler.py	2008-04-17 21:25:10.000000000 +0200
+++ happycamel-v1-beta3-ds/HappyCamel/photohandler.py	2008-11-19 14:22:55.000000000 +0100
@@ -164,7 +164,7 @@
     if ((not self.ele) or overwrite):
       self.ele = ele
 
-  def __scalePhoto__(self, file_obj, max_side):
+  def __scalePhoto__(self, file_obj, max_side, icon_size = 0):
     """ Scale the photo referred to by the given file_obj so that the longest
         size is max_side. If the original is smaller than the required format,
         it isn't scaled. Return a JPEG-encoded string with data. """
@@ -195,7 +195,24 @@
         self.logger.debug("Required thumbnail for %s is larger than the original - no scaling." % self.getName())
         
       # Return a JPEG encoded string
-      return photo_data.tostring("jpeg", "RGB")
+      thumbnail = photo_data.tostring("jpeg", "RGB")
+      
+      if (icon_size):
+        if (photo_size[0] > photo_size[1]):
+          fraction = float(icon_size) / photo_size[0]
+        else:
+          fraction = float(icon_size) / photo_size[1]
+	
+	if (fraction < 1.0):
+    	  icon_size = [int(photo_size[0] * fraction), int(photo_size[1] * fraction)]
+          self.logger.debug("Resizing thumnail %s from %dx%d to %dx%d pixels." % (self.getName(), thumbnail_size[0], thumbnail_size[1], icon_size[0], icon_size[1]))
+    	  photo_data.thumbnail(icon_size, Image.BICUBIC)
+    	
+	icon = photo_data.tostring("jpeg", "RGB")
+      else:
+        icon = None
+
+      return thumbnail, icon
 
     return False
 
@@ -543,7 +560,7 @@
     results.update(self.__queue2Dict__(flickr_results))
     return results
     
-  def getThumbnailData(self, max_side, queue):
+  def getThumbnailData(self, max_side, icon_size, queue):
     """ Load all the thumbnails from the images in the list and put a tuple of
         (photo object, JPEG-encoded thumbnail data) in the provided Queue.queue
         instance. This allows for a multithreaded processing of the images.
@@ -558,9 +575,9 @@
     
     # Process the pools
     self.__runThreaded__(self.DISK_THREAD_NUM, "getThumbnailData",
-                         pools["disk"], queue, max_side = max_side)
+                         pools["disk"], queue, max_side = max_side, icon_size = icon_size)
     self.__runThreaded__(self.FLICKR_THREAD_NUM, "getThumbnailData",
-                         pools["flickr"], queue, max_side = max_side)
+                         pools["flickr"], queue, max_side = max_side, icon_size = icon_size)
 
   def cleanup(self, check_date = False, check_location = False):
     """ Removes the photos from the list which don't comply to the specified
@@ -757,7 +774,7 @@
 
     return "file://%s" % os.path.join(os.getcwd(), self.getPath())
 
-  def getThumbnailData(self, max_side = 200):
+  def getThumbnailData(self, max_side = 200, icon_size = 0):
     """ Convert the image to a thumbnail and return the data, JPEG-encoded,
         or False if we cannot convert this image. max_side specifies the number
         of pixels the long side of the thumbnail needs to have. """
@@ -767,7 +784,7 @@
     if (ext in PIL_READ_FORMATS):
       self.logger.debug("Creating thumbnail for photo %s" % self.getName())
       photo_data = open(self.getPath())
-      return self.__scalePhoto__(photo_data, max_side)
+      return  self.__scalePhoto__(photo_data, max_side, icon_size)
     else:
       self.logger.error("Can't create thumbnail for photo %s" % self.getName())
       return False
@@ -1270,7 +1287,7 @@
 
     return True
 
-  def getThumbnailData(self, max_side = 200):
+  def getThumbnailData(self, max_side = 200, icon_size = 0):
     """ Convert the image to a thumbnail and return the data, JPEG-encoded,
         or False if we cannot convert this image. max_side specifies the number
         of pixels the long side of the thumbnail needs to have. """
@@ -1312,7 +1329,7 @@
       
     # Download the photo and load it as a PIL image
     photo_data = StringIO.StringIO(urllib2.urlopen(best_fit["entry"]["source"]).read())
-    return self.__scalePhoto__(photo_data, max_side)
+    return self.__scalePhoto__(photo_data, max_side, icon_size)
 
   def writeMetadata(self, write_coords = True, write_geo_names = False,
                     correct_time = False):