I have a photo page with a jquery cropper loaded on an image. When satisfied with the crop dimensions, the user clicks a button and a method is called to crop the image.
'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);
});
}
I use graphics magic to crop the image and it works. However to see the image cropped you have to refresh the page manually, which is not what I want to do. I wrote the following code in the photo helper, but it does not change the photo even though the re subscription takes place. The page still needs to be refreshed.
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"});
}
});