gpt4 book ai didi

javascript - 添加新的 Meteor CollectionFS 存储

转载 作者:行者123 更新时间:2023-11-28 01:02:43 26 4
gpt4 key购买 nike

我一直在使用 CollectionFS 和 GraphicsMagick 来裁剪图像并将其存储在 S3 中。我意识到这些图像对于移动设备来说太大了,现在我想存储缩小的版本。这是我尝试过的。

images = new FS.Collection("images", {
stores: [
new Store("images", imageOptions),
new Store("thumbs", thumbOptions) // added later
]
});

thumbs 存储适用于新图像,但缩小旧图像的启动功能则不适用于。

Meteor.startup(function () {
images.find().forEach(function (fileObj) {
if (!fileObj.copies.thumbs) {
var readStream = fileObj.createReadStream('images');
var writeStream = fileObj.createWriteStream('thumbs');
gm(readStream)
.scale(THUMB_DIM, THUMB_DIM)
.stream()
.pipe(writeStream);
}
});
});

有什么想法吗?是否是由来自 S3readstream 引起的?

最佳答案

似乎您缺少 gm 命令中的第二个参数,该参数应该是原始文件名。我们使用以下迁移脚本在新商店中创建图像的副本:

Migrations.add({
version: 2,
name: 'Save old images to new image stores',
up: function() {
console.log('Save old images to new image stores');
Images.find().fetch().forEach(function(image) {
if (image.copies['32x32'].size === 0) {
console.log('creating 32x32 image: ' + image.name());
var readStream = image.createReadStream('original');
var writeStream = image.createWriteStream('32x32');
try {
gm(readStream, image.name()).resize(32, 32).stream().pipe(writeStream);
}
catch (e) {
console.log(e);
}
}
if (image.copies['80x80'].size === 0) {
console.log('creating 80x80 image: ' + image.name());
var readStream = image.createReadStream('original');
var writeStream = image.createWriteStream('80x80');
try {
gm(readStream, image.name()).resize(80, 80).stream().pipe(writeStream);
}
catch (e) {
console.log(e);
}
}
});
},
down: function() {
}
});

关于javascript - 添加新的 Meteor CollectionFS 存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25439269/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com