I have a live stream coming from the camera using webcamjs which is terrific and I am very happy. However it is giving 320 by 240 image and I want some way in which I can show only 160 by 120 to the user.
Is there any way to accomplish this using HTML or JavaScript or jQuery?
Let me describe it more...
In chrome I have limited the display area through CSS by using width and height properties, but when I open in IE, it uses flash and it does not even show up.
<form>
.....
.....
<td>Photo</td>
<td><input id="photo7" type="file" name="photo">
</td>
<div style="width: 320px; height: 240px; clear: right; float: right">
<div id="takesnap11"
style="clear: both; float: right; text-align: center;"></div>
<div id="my_camera" style="width: 320px; height: 240px; "></div>
<img id="results2" height="120" width="160" />
</div>
<script src="../js/webcam.min.js" type="text/javascript"></script>
<script>
</script>
</form>
</section>
<script>
function Initiate(){
Webcam.set({
image_format: 'jpeg',
jpeg_quality: 90,
dest_width: 160,
dest_height: 120,
force_flash: false
});
Webcam.attach( '#my_camera' );
document.getElementById("takesnap11").innerHTML='<div onclick="take_snapshot();">Take Snap</div>';
}
function take_snapshot() {
var data_uri = Webcam.snap();
document.getElementById('resultssss').innerHTML ='<textarea style="width: 90px;" style="display:none" name="capturedimage"> '+data_uri+'</textarea>';
document.getElementById('results2').src = data_uri;
}
</script>
<script src="../js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script>
$('#photo7').on('change', function(ev) {
var f = ev.target.files[0];
var fr = new FileReader();
fr.onload = function(ev2) {
console.dir(ev2);
$('#results2').attr('src', ev2.target.result);
document.getElementById('resultssss').innerHTML ='<textarea style="width: 90px;" style="display:none" name="capturedimage"> '+ev2.target.result+'</textarea>';
};
fr.readAsDataURL(f);
});
</script>
The user has the option to use a photo upload and hence that photo tag there. I know this is something with the canvas any help appreciated...
Thanks,
Abhijeet.
Disclaimer: I don't use webcamJS, but...
A quick look at the source code reveals you can set a couple of properties in Webcam.set
which will cause the image to be cropped:
crop_width:160,
crop_height:120,
For more info about how it works (using the clipping version of context.drawImage), refer to the source at lines 416-425: