18
loading...
This website collects cookies to deliver better user experience
navigator.getUserMedia API
but there's an react package that simplifies the whole process.yarn add react-webcam
getScreenshot({width: 1920, height: 1080})
to take a 1080p snapshot of the user.Any browser can only run javascript on the client, so we've to run python on the server
axios.post(url, { image: imageSrc, color: selectedColor })
I also send the selected color, as I need it for the application that I'm building
Unless you used an image optimizer like I did in a previous project
app.use(bodyParser.json({ limit: "5mb" }));
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKsAAADVCAMAAAAfHvCaAAAAGFBMVEVY
iVBORw0KGgoAAAANSUhEUgAAAKsAAADVCAMAAAAfHvCaAAAAGFBMVEVY
const base64Image = req.body.image.split(";base64,").pop();
const fs = require("fs");
fs.writeFileSync("input/image.png", base64Image, { encoding: "base64" });
const { spawn } = require("child_process");
const py = spawn("python", ["color-filter.py", body.color]);
var data2send
py.stdout.on("data", (data) => {
data2send = data.toString();
});
console.log(data2send);
py.on("close", () => {
// Adding Heading and converting image to base64
const image = `data:image/png;base64,${fs.readFileSync("output/image.png", {
encoding: "base64",
})}`;
// sending image to client
res.json({ image });
});
Standard Deploy Node to Heroku
Heroku Node App Deployment Docs
Add Python Packages
In the JavaScript World we have a package.json
which tells every node instance all the packages required to run
requirements.txt
to replicate that behavior..gitignore
file// requirements.txt
numpy
cv2
matplotlib
requirements.txt
file it runs pip install -r requirements.txt
, hence installing all the required packages// terminal
// This command will set your default buildpack to Node.js
heroku buildpacks:set heroku/nodejs
// This command will set it up so that the Heroku Python buildpack will run first
heroku buildpacks:add --index 1 heroku/python