Skip to content

Commit

Permalink
Slightly clean up the final URL creation in canvas.toDataURL
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Oct 3, 2018
1 parent a339261 commit cfd4462
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions components/script/dom/htmlcanvaselement.rs
Expand Up @@ -396,19 +396,16 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
},
};

// Only handle image/png for now.
let mime_type = "image/png";

let mut encoded = Vec::new();
{
let encoder: PNGEncoder<&mut Vec<u8>> = PNGEncoder::new(&mut encoded);
encoder
.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8))
.unwrap();
}

let encoded = base64::encode(&encoded);
Ok(USVString(format!("data:{};base64,{}", mime_type, encoded)))
// FIXME: Only handle image/png for now.
let mut png = Vec::new();
PNGEncoder::new(&mut png)
.encode(&raw_data, self.Width(), self.Height(), ColorType::RGBA(8))
.unwrap();
let mut url = "data:image/png;base64,".to_owned();
// FIXME(nox): Should this use base64::URL_SAFE?
// FIXME(nox): https://github.com/alicemaz/rust-base64/pull/56
base64::encode_config_buf(&png, base64::STANDARD, &mut url);
Ok(USVString(url))
}
}

Expand Down

0 comments on commit cfd4462

Please sign in to comment.