GithubHelp home page GithubHelp logo

Comments (8)

jhuckaby avatar jhuckaby commented on July 19, 2024

Unfortunately I don't know of a native way to do this. There doesn't appear to be an API to get the camera dimensions in either getUserMedia (HTML5) or in Adobe Flash. The best way I've found to deal with this is to always capture in 4:3 aspect ratio, and then crop your desired rectangle/square out of the center of the image after capture (using HTML5 Canvas, or on the server using GD or ImageMagick).

I may add an API to do this for you, in an upcoming version of WebcamJS.

from webcamjs.

mfkp avatar mfkp commented on July 19, 2024

There's videoHeight and videoWidth attributes on a video element, which you can use to calculate the aspect ratio.

from webcamjs.

Krakabek avatar Krakabek commented on July 19, 2024

mfkp, thanks.
I found, how to do it, but the only problem is that I can't calculate it before I attach the camera and start streaming.

from webcamjs.

mfkp avatar mfkp commented on July 19, 2024

You might need to start it up, get the video element, calculate the aspect ratio, then do Webcam.reset() and initialize it again with the new values.

Could be a better way to do it, but nothing is coming to mind right now.

from webcamjs.

Krakabek avatar Krakabek commented on July 19, 2024

A bit weird way, but it's the only thing came to my ming too.
For my purpose I've saved videoH and videoW, and after making a snapshot do some math to resize taken image to proportional size
(By the way, about resize() method - Look at the issue #25
There are some troubles and I solved it, but I can't commit changes)

from webcamjs.

jhuckaby avatar jhuckaby commented on July 19, 2024

Looks like videoWidth / videoHeight are only available with getUserMedia (Chrome & Firefox only). I don't see a way to do it with the Flash fallback (Safari / IE). For now, I'm going to try my "post-crop" idea, and will continue to look at a universal way to support this. Thanks guys.

from webcamjs.

jhuckaby avatar jhuckaby commented on July 19, 2024

Hey guys, I have implemented an automatic "crop" feature which can be used if you want to capture a square image. The idea is, the engine will capture at 4:3 aspect ratio (as 99.99999% of all webcams support that), but then it'll crop a square (or any rectangle shape) out of the center for you, all handled automatically in the background, and reflected in the live preview as well.

Live Demo: http://pixlcore.com/demos/webcamjs/demos/crop.html

from webcamjs.

Zireael07 avatar Zireael07 commented on July 19, 2024

Live demo shows an error :(

from webcamjs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.