Search code examples
javascriptmobilemeteorcamera

How to implement web camera and mobile camera on Meteor


I need to implement a photo capture on Meteor. Is there any Meteor package to achieve image capturing?


Solution

  • I'm using the mdg:camera package. It's simple and useful.

    meteor add mdg:camera
    

    First you can create a link on the html side.

    <template name="example">
        <a href="#" class="takePhoto">take photo</a>
        <img class="photo">
    </template>
    

    After clicking, you can change the captured picture.

    Template.example.events({
        'click .takePhoto': function(e, instance) {
            e.preventDefault();
    
            var cameraOptions = {
                width: 800,
                height: 600
            };
    
            MeteorCamera.getPicture(cameraOptions, function (error, data) {
               if (error) {
                   return; // here maybe you can give an error.
               }
    
               instance.$('.photo').attr('src', data);
            });
        }
    });
    

    You can also check here for some picture options:

    https://github.com/meteor/mobile-packages/blob/master/packages/mdg:camera/README.md#meteorcameragetpictureoptions-callback