Skip to content

Commit

Permalink
修复缩略图bug
Browse files Browse the repository at this point in the history
  • Loading branch information
www committed Sep 8, 2021
1 parent 0495b4a commit 8e0e740
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions admin/controller/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ class Upload extends Base
const cfg_width = parseInt(this.site.img_width) || 0;
const cfg_height = parseInt(this.site.img_height) || 0;

image.quality(80);

// 限制图片大小
if((cfg_width && image.getWidth() > cfg_width) || (cfg_height && image.getHeight() > cfg_height)) {
if(image.getWidth() > this.site.img_width && image.getWidth() / image.getHeight() > cfg_width / cfg_height) {
await image.resize(cfg_width, jimp.AUTO);
image.resize(cfg_width, jimp.AUTO);
} else {
await image.resize(jimp.AUTO, cfg_height);
image.resize(jimp.AUTO, cfg_height);
}
await image.writeAsync(img_path);
}
Expand All @@ -50,7 +52,7 @@ class Upload extends Base
const thumb_height = parseInt(this.site.thumb_height) || 0;
if((thumb_width && image.getWidth() > thumb_width) || (thumb_height && image.getHeight() > thumb_height)) {
thumb_path = thumb_path.replace('.' + result.extname, '_lit.' + result.extname);
await image.resize(thumb_width, thumb_height);
image.cover(thumb_width, thumb_height);
await image.writeAsync(thumb_path);
}

Expand Down Expand Up @@ -100,8 +102,8 @@ class Upload extends Base
if(thumb_path != img_path && utils.fs.isFileSync(thumb_path)) {
await utils.fs.unlink(thumb_path);
}

await this.$model.upload.delete({id});

this.$success('删除成功!', 'index');
} catch(e) {
this.$error('删除失败!');
Expand Down

0 comments on commit 8e0e740

Please sign in to comment.