-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
thumbnail.js
29 lines (26 loc) · 1.1 KB
/
thumbnail.js
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
// Bing Wallpaper GNOME extension
// Copyright (C) 2017-2023 Michael Carroll
// This extension is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// See the GNU General Public License, version 3 or later for details.
import Gio from 'gi://Gio';
import GdkPixbuf from 'gi://GdkPixbuf';
const THUMBNAIL_WIDTH = 480;
const THUMBNAIL_HEIGHT = 270;
export default class Thumbnail {
constructor(filePath, scale = 1.0) {
if (!filePath) {
throw new Error(`need argument ${filePath}`);
}
try {
let w = Math.round(THUMBNAIL_WIDTH * scale);
let h = Math.round(THUMBNAIL_HEIGHT * scale);
this.pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(filePath, w, h);
this.srcFile = Gio.File.new_for_path(filePath);
} catch (err) {
log('Unable to create thumbnail for corrupt or incomplete file: ' + filePath + ' err: ' + err);
}
}
};