Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Experiment: svg trace Image data? #104

Closed
wants to merge 3 commits into from
Closed

Experiment: svg trace Image data? #104

wants to merge 3 commits into from

Conversation

mrkurt
Copy link
Member

@mrkurt mrkurt commented Jul 6, 2018

This is a discussion PR. So discuss!

This adds a traceSVG function on the Image object that gives back an SVG string of the traced output. You can also pass posterize to it, just for fun.

This is using an additional Node library, which I don't love. I experimented with some pure JS SVG tracing implementations and couldn't find a good alternative, though. And I looked for a wasm one and couldn't find anything. That said, I'm not offended at how this works either! It's a pretty nice/simple dev facing API.

Here are some examples:

import { Image } from '@fly/image'
const url = "https://raw.githubusercontent.com/superfly/fly/147f2a327dc76ce6cf10c46b7ea1c19a9d8f2d87/v8env_test/fixtures/picture.jpg"

fly.http.respondWith(async function (req) {
  let resp = await fetch(url)
  let body = await resp.arrayBuffer()
  //return resp
  let svg = new Image(body).traceSVG("posterize")

  return new Response(
    `<html><body>${svg}<br><br><img src="${url}"></body></html`,
    {
      headers: { "Content-Type": "text/html" }
    }
  )
})

Trace on a logo:
image

Posterize on a photo:
image

@mrkurt mrkurt added the question label Jul 6, 2018
@mrkurt mrkurt added the rust+v8 label Dec 5, 2018
@mrkurt mrkurt closed this Dec 5, 2018
@mrkurt mrkurt deleted the traced-svg branch June 17, 2020 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant