Skip to content

Commit

Permalink
Flip wecam left-right to behave like mirrow
Browse files Browse the repository at this point in the history
much more natural
  • Loading branch information
Dave Conway-Jones committed Oct 27, 2020
1 parent a4267f5 commit fb716fd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion node-red-node-ui-webcam/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-red-node-ui-webcam",
"version": "0.2.0",
"version": "0.2.1",
"description": "A Node-RED ui node to capture images from a webcam.",
"author": "Nick O'Leary",
"license": "Apache-2.0",
Expand Down
7 changes: 2 additions & 5 deletions node-red-node-ui-webcam/ui_webcam.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
category: 'dashboard',
color: 'rgb( 63, 173, 181)',
defaults: {
name: {value: ''},
group: {type: 'ui_group', required:true},
order: {value: 0},
width: {
Expand All @@ -29,8 +30,7 @@
$("#node-input-size").toggleClass("input-error",!valid);
return valid;
}},
height: {value: 0},
name: {value: ''},
height: {value: 5},
countdown: { value: false },
autoStart: { value: false },
hideCaptureButton: { value: false },
Expand Down Expand Up @@ -87,7 +87,6 @@
})

$("#node-input-showImage-enable").trigger("change");

},
oneditsave: function() {
var showImageEnable = $("#node-input-showImage-enable")[0].checked;
Expand All @@ -101,7 +100,6 @@
} else {
this.showImage = showImageTime;
}

}
});
</script>
Expand Down Expand Up @@ -154,7 +152,6 @@
</select>
</div>
</div>

</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
Expand Down
9 changes: 6 additions & 3 deletions node-red-node-ui-webcam/ui_webcam.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ module.exports = function(RED) {
position: absolute;
width: 100%;
height: 100%;
-webkit-transform: scaleX(-1);
transform: scaleX(-1);
}
.ui-webcam-playback-container {
width: 100%;
Expand Down Expand Up @@ -211,8 +213,6 @@ module.exports = function(RED) {
var activeCamera = null;
var oldActiveCamera = null;



$scope.changeCamera = function(deviceId) {
oldActiveCamera = activeCamera;
activeCamera = $scope.data.cameras[deviceId].deviceId;
Expand Down Expand Up @@ -325,7 +325,10 @@ module.exports = function(RED) {
var canvas = document.querySelector("canvas#ui_webcam_canvas_"+$scope.$id);
canvas.width = playbackEl.videoWidth;
canvas.height = playbackEl.videoHeight;
canvas.getContext('2d').drawImage(playbackEl, 0, 0);
var ctx = canvas.getContext('2d');
ctx.translate(playbackEl.videoWidth, 0);
ctx.scale(-1, 1);
ctx.drawImage(playbackEl, 0, 0);
var img = document.querySelector("img#ui_webcam_image_"+$scope.$id);
img.src = canvas.toDataURL('image/'+($scope.config.format||'png'));
if ($scope.config.showImage) {
Expand Down

0 comments on commit fb716fd

Please sign in to comment.