instead of showing a gigantic javascript script could you just send a project showing it off?
even better, make it in vanilla snap.
vanilla snap for this is nearly impossible im pretty sure
also you can drag the script pic in if you wanna test it out
unless i cld do a costume to url block
Actually, to make it feel more like it's in snap, you can actually start snap's built in video capture (which displays the video on the stage), and then you can get the video image.
let stage = this.parentThatIsA(StageMorph) // get the stage
stage.startVideo() // this will show the video on the stage
stage.projectionLayer() // this will return a canvas element, which contains the current camera image
Of course, you can also start the video in snap using the set [video capture V] to <t>
block.
If you use these, you won't need to create your own popup with the camera.
i just wanna be able to convert an image to base 64. its time snap add to the pixels library
It can be simplified to QRCode from costume
.
Used for
.
.
Scanning by the webcam
still has js
But it's less js than what you originally had.
I personally think that js can be used, but only in moderation, and cases where you just can't do it in snap. This case right here, the only thing you can't do without js, is using that js library to scan the image, and get the data from it. I personally think that's the easiest way to do what you want.
However, if you're feeling like it, you could try and create your own qr code reader in snap, because it is technically possible, it would just most likely be slow, and take a very long time (and research) to make.
can we not use primitives for the library i just dont like that u have to turn on js. i think there should be a way to submit js blocks and have them scanned for malicious stuff and if it comes up that its ok you dont need to turn on js for it
You can technically create your own javascript extension, which will allow you to put your own functions in extension [ V] [] @delInput @verticalEllipsis @addInput
, which, if the snap devs like your extension, can whitelist it, which will allow your js function to run without javascript (although, they have really only whitelisted some bigger libraries, like tunescope and scisnap).
I don't think there should be any automated system to determine if your javascript function is save, because, what constitutes as safe and dangerous? I also don't think jens wants to put a large javascript antivirus into snap, because that would make snap very bloated. Plus, the reason you have to manually enable js, is because users should (but usually don't) look through the js code, and determine if it's safe or not, all by themselves.
The thing you're looking for, just isn't possible without js, so you're not going to find some solution without js (unless there's some api that can take a list of pixels, and convert that to a base64 image string, but then again, I'm pretty sure urls have a character limit, which wouldn't work very well with this).
GET requests have a character limit, iirc, which is why most APIs handling movement of large amounts of data use POST.
You can use the user script manager to install a "private" extension
QRCode user script
// ==UserScript==
// @name Snap! QRCode
// @namespace http://tampermonkey.net/
// @version 2024-09-08
// @description QRCode extension for Snap
// @author DarDoro@SNAP forum
// @match https://snap.berkeley.edu/snap/snap.html
// ==/UserScript==
(function() {
'use strict';
SnapExtensions.urls.push('https://cdn.jsdelivr.net/npm/jsqr');
SnapExtensions.primitives.set(
'qrc_detect'
,function( cst, w, h){
let imgData = cst?.contents?.getContext( "2d")?.getImageData(0, 0, w, h)
let qrData = jsQR( imgData.data, w, h);
return qrData ? qrData.data :"";
}
)
})();
And