wolfyflutter

www.pixelcut.ai [ai] [image upscale]

Jun 14th, 2025 (edited)
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 1.75 KB | Source Code | 0 0
  1. /*  base   : https://www.pixelcut.ai/image-upscaler
  2.     fungsi : buat upscale image lu
  3.     note   : kali ini gw makek libary formdata-node
  4.              bukan form-data yah. beda karena gw gk
  5.              makek axios.
  6.              jadi pastiin lu install dulu tuh lib :v
  7.              males gw hardcode formdata wkwkwk.
  8.              oh ya lu cuma dapetin upscale image 2x
  9.              di situs nya bisa ampe 4x sebenarnya
  10.              cuma pas gw ganti value di form data,
  11.              yang scale jadi 4, dia error 401
  12.              Unauthorized.
  13.              kali ini gw bikin single function ajah,
  14.              jenis async, param buffer, return objet json.
  15.              di json ada link download image yg udh
  16.              di upscale.
  17.     by     : wolep
  18.     update : 15 Juli 13:09 Wita
  19. */
  20.  
  21. const { FormData } = require("formdata-node")
  22.  
  23. const removeBackground = async (imageBuffer) => {
  24.     if (!imageBuffer?.length) throw Error (`mana file nya`)
  25.  
  26.     const body = new FormData()
  27.     body.append("image", new Blob([imageBuffer]))
  28.     body.append("scale", "2")
  29.  
  30.     const headers = {
  31.         "accept": "application/json",
  32.         "x-client-version": "web",
  33.         ...body.headers
  34.     }
  35.  
  36.     const response = await fetch("https://api2.pixelcut.app/image/upscale/v1", {
  37.         headers, body, "method": "POST"
  38.     })
  39.  
  40.     if(!response.ok) throw Error (`${response.status} ${response.statusText}\n${await response.text() || null}`)
  41.     return await response.json()
  42. }
  43.  
  44. // cara pakai
  45. const buffer = require('fs').readFileSync("./furry.jpeg")
  46.  
  47. removeBackground(buffer)
  48. .then(console.log)
  49. .catch(err => console.log(err.message))
  50.  
  51. /* output
  52. {
  53.   result_url: 'https://cdn2.pixelcut.app/temp/upscale/077023de-04a2-40c9-91e8-e302628b91f0.jpg'
  54. }
  55. */
Advertisement
Add Comment
Please, Sign In to add comment