Skip to content

Commit fb70ab2

Browse files
committed
Add option to skip extracting thumbnails
1 parent 2aa60df commit fb70ab2

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/main.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ struct PhotoInfo {
3232
date: String,
3333
}
3434

35+
enum ThumbMode {
36+
None,
37+
Exif,
38+
}
39+
40+
impl ThumbMode {
41+
fn create_dir(&self, thumbs_dir: &str) -> Result<(), std::io::Error> {
42+
match self {
43+
ThumbMode::Exif => fs::create_dir_all(thumbs_dir),
44+
_ => Ok(()),
45+
}
46+
}
47+
}
48+
3549
fn main() -> ExitCode {
3650
let dir = env::args_os()
3751
.nth(1)
@@ -43,7 +57,8 @@ fn main() -> ExitCode {
4357
}
4458

4559
let thumbs_dir = "thumbs";
46-
if let Err(e) = fs::create_dir_all(thumbs_dir) {
60+
let thumb_mode = ThumbMode::Exif;
61+
if let Err(e) = thumb_mode.create_dir(thumbs_dir) {
4762
eprintln!("Could not create {} directory: {}", thumbs_dir, e);
4863
return ExitCode::FAILURE;
4964
}
@@ -101,8 +116,12 @@ fn main() -> ExitCode {
101116
let make = get_string(&exif, Tag::Make).unwrap_or(UNKNOWN.to_string());
102117
let model = get_string(&exif, Tag::Model).unwrap_or(UNKNOWN.to_string());
103118
let date = get_datetime(&exif, Tag::DateTimeOriginal).unwrap_or(UNKNOWN.to_string());
104-
let thumb = get_thumbnail_data(&exif)
105-
.and_then(|data| save_thumbnail(format!("{}/t{}.jpg", thumbs_dir, idx), data))?;
119+
let thumb = match thumb_mode {
120+
ThumbMode::Exif => get_thumbnail_data(&exif).and_then(|data| {
121+
save_thumbnail(format!("{}/t{}.jpg", thumbs_dir, idx), data)
122+
})?,
123+
_ => "".to_string(),
124+
};
106125

107126
Some(PhotoInfo {
108127
name,

src/map.html

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ <h3>{name}</h3>
116116
} else {
117117
// Show photo details
118118
const details = features.map(f => photoDetails(f));
119-
document.getElementById('photo-details').innerHTML = details.join();
119+
document.getElementById('photo-details').innerHTML = details.join("");
120120
}
121121
});
122122
});
@@ -125,7 +125,7 @@ <h3>{name}</h3>
125125
const transform = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
126126
items.forEach(item => {
127127
const feature = new ol.Feature(item);
128-
feature.set('url', item.thumb);
128+
feature.set('url', item.thumb ? item.thumb : thumbnail(item.name));
129129
const coordinate = transform([parseFloat(item.lon), parseFloat(item.lat)]);
130130
feature.setGeometry(new ol.geom.Point(coordinate));
131131
photosSource.addFeature(feature);
@@ -187,6 +187,24 @@ <h3>{name}</h3>
187187
return [photoStyle(feature, clamp(0.2, 0.1 / resolution, 1))];
188188
}
189189

190+
function thumbnail(str) {
191+
const hue = hueColor(str);
192+
const svg = `
193+
<svg width="160" height="120" xmlns="http://www.w3.org/2000/svg">
194+
<rect width="100%" height="100%" fill="hsl(${hue}, 60%, 50%)" stroke="hsl(${hue}, 55%, 30%)" stroke-width="2"/>
195+
</svg>
196+
`.trim();
197+
return `data:image/svg+xml;base64,${btoa(svg)}`;
198+
}
199+
200+
function hueColor(str) {
201+
let hash = 0;
202+
for (let i = 0; i < str.length; i++) {
203+
hash = str.charCodeAt(i) + ((hash << 5) - hash);
204+
}
205+
return hash % 360;
206+
}
207+
190208
function clamp(min, value, max) {
191209
if (value < min) return min;
192210
if (value > max) return max;

0 commit comments

Comments
 (0)