Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* base : https://www.pixelcut.ai/image-upscaler
- fungsi : buat upscale image lu
- note : kali ini gw makek libary formdata-node
- bukan form-data yah. beda karena gw gk
- makek axios.
- jadi pastiin lu install dulu tuh lib :v
- males gw hardcode formdata wkwkwk.
- oh ya lu cuma dapetin upscale image 2x
- di situs nya bisa ampe 4x sebenarnya
- cuma pas gw ganti value di form data,
- yang scale jadi 4, dia error 401
- Unauthorized.
- kali ini gw bikin single function ajah,
- jenis async, param buffer, return objet json.
- di json ada link download image yg udh
- di upscale.
- by : wolep
- update : 15 Juli 13:09 Wita
- */
- const { FormData } = require("formdata-node")
- const removeBackground = async (imageBuffer) => {
- if (!imageBuffer?.length) throw Error (`mana file nya`)
- const body = new FormData()
- body.append("image", new Blob([imageBuffer]))
- body.append("scale", "2")
- const headers = {
- "accept": "application/json",
- "x-client-version": "web",
- ...body.headers
- }
- const response = await fetch("https://api2.pixelcut.app/image/upscale/v1", {
- headers, body, "method": "POST"
- })
- if(!response.ok) throw Error (`${response.status} ${response.statusText}\n${await response.text() || null}`)
- return await response.json()
- }
- // cara pakai
- const buffer = require('fs').readFileSync("./furry.jpeg")
- removeBackground(buffer)
- .then(console.log)
- .catch(err => console.log(err.message))
- /* output
- {
- result_url: 'https://cdn2.pixelcut.app/temp/upscale/077023de-04a2-40c9-91e8-e302628b91f0.jpg'
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment