我有一张带有jquery裁剪器的照片页面。当对裁剪尺寸感到满意时,用户单击按钮并调用方法来裁剪图像。
'update_crop': function(
fileObj_id, photoSpec
)
{
PhotoCollection.find({"_id" : fileObj_id}).forEach(function (fileObj) {
console.log("Photo Spec in server: " + photoSpec.x);
var readStream = fileObj.createReadStream('ImageStore');
var writeStream = fileObj.createWriteStream('ImageStore');
gm(readStream, fileObj.name()).crop(photoSpec.width, photoSpec.height, photoSpec.x, photoSpec.y).stream().pipe(writeStream);
});
}
我使用图形魔法来裁剪图像并且它有效。但是,要查看裁剪的图像,您必须手动刷新页面,这不是我想要做的。我在照片助手中编写了以下代码,但即使重新订阅发生也不会更改照片。该页面仍需要刷新。
Template.profile_photo.helpers({
replace_upload_photo: function() {
return Session.get("replace_upload_photo");
},
profile_photo: function() {
var controller = Iron.controller();
var id = controller.state.get('profileId');
var photoHandle = Meteor.subscribe('profile_photo', id);
if (Session.get("crop")) {
console.log
photoHandle.stop(); //Deletes the profile photo subscription and re subscribes by using the handler
Session.set("crop", false);
photoHandle = Meteor.subscribe('profile_photo', id);
}
return PhotoCollection.findOne({parentId: id, photoType: "profile"});
}
});