thumbnail.js 1.1 KB

1234567891011121314151617181920212223242526272829
  1. // Bing Wallpaper GNOME extension
  2. // Copyright (C) 2017-2023 Michael Carroll
  3. // This extension is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU Lesser General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. // See the GNU General Public License, version 3 or later for details.
  8. import Gio from 'gi://Gio';
  9. import GdkPixbuf from 'gi://GdkPixbuf';
  10. const THUMBNAIL_WIDTH = 480;
  11. const THUMBNAIL_HEIGHT = 270;
  12. export default class Thumbnail {
  13. constructor(filePath, scale = 1.0) {
  14. if (!filePath) {
  15. throw new Error(`need argument ${filePath}`);
  16. }
  17. try {
  18. let w = Math.round(THUMBNAIL_WIDTH * scale);
  19. let h = Math.round(THUMBNAIL_HEIGHT * scale);
  20. this.pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(filePath, w, h);
  21. this.srcFile = Gio.File.new_for_path(filePath);
  22. } catch (err) {
  23. log('Unable to create thumbnail for corrupt or incomplete file: ' + filePath + ' err: ' + err);
  24. }
  25. }
  26. };