0

I'm trying to determine the width of an image stored in GridFS on meteor so that I can re-size a modal dialog.

I have a helper for the template

Template.projectImageModalInner.image = function() {
    var imageId = Session.get("selectedImageId");
    //console.log("projectImageModalInner imageId: " +imageId);
  var image = imageFS.findOne({_id: imageId});
  url = image.fileHandler.default1.url;
  console.log(url);
    console.log(Imagemagick.identify(url));
  return imageFS.findOne({_id: imageId});
}

which returns the correct image to the dialog to display, but I'm really having problems getting the size. The call to Imagemagick.identify blows up with an error saying "cannot call method identify on undefined" yet the line above prints the correct url.

The console log for the image url shows

/cfs/images/i5mSRED6mYgo2vK84_default1.jpg 

which is the correct URL of the image being displayed in the template.

I want to set a session variable eventually with the image width so that the dialog can be dynamically sized.

I have tried getting this size from the html (with no joy), from other helpers but so far nothing is working.

Can anyone either point out what I'm doing wrong here, OR, suggest another way?

joao
  • 4,067
  • 3
  • 33
  • 37
Peter Nunn
  • 2,110
  • 3
  • 29
  • 44
  • This doesn't appear to be core meteor unless I'm missing something. Perhaps provide more information around your `imageFS` definition. At any rate the solution will be to do this server side, as opposed to any client side code. – Neil Lunn Feb 17 '14 at 06:49
  • I would first guess that imagemagick is only available on the server? At any rate, the solution I would propose would be, load the image in the background in JS then get its dimensions, and then create the modal. – 1321941 Feb 17 '14 at 12:40
  • Neil: The packages being used here are meteor-imagemagick and gridfs both from meteorite. Mr D. How would you do this in the background? I have no idea where to start. – Peter Nunn Feb 17 '14 at 22:44

1 Answers1

2

I think you have to use the graphicsmagick / imagemagick library on the server-side after the upload to get the image size.

First, use the transformWrite function on the server collection to get image dimensions with gm.size(), then attach those values to the fileObj.metadata.

Check those two how-to's explaining all the relevant parts:

Thomas
  • 446
  • 4
  • 10