v2.0.3

Image, File and Video Extensions

Last updated


Clipboard, download, and re-encoding on Image, thumbnail extraction on File, and one-call configuration on <video> elements.

Image


Source: src/prototype/Image.ts
Method / PropertyDescription
img.copy(mime = "image/jpeg")Async; copies the image to the clipboard via ClipboardItem
img.download(mime = "image/jpeg", filename?)Triggers a browser download using an object-URL <a download> link
img.$base64(mime, size?)Re-encodes via an offscreen <canvas>; size (if smaller than the longest side) proportionally downscales the image first
img.$blob(mime, size?)$base64 decoded back into a Blob

File


Source: src/prototype/File.ts
MethodDescription
file.$image(isVideo = false)Returns a Promise<Image>. For images, decodes via FileReader.readAsDataURL. For video files (isVideo: true), reads the file into a muted offscreen <video>, starts playback, and on loadeddata draws the current frame onto a <canvas> to produce a JPEG thumbnail

HTMLVideoElement


Source: src/prototype/HTMLVideoElement.ts
MethodDescription
video._config({ preload, loop, muted, controls, playsinline, download, remote })Chainable one-call setup: always disables the native download/remote-playback UI via controlsList, then applies each provided flag (download: false/remote: false re-add the corresponding controlsList token)

Example


_config writes every flag in one call; $base64 re-encodes through a canvas.
  1. <video id="video"></video>
  2. <script>
  3. "video".$._config({ muted: true, loop: true, controls: true, playsinline: true });
  4. console.log("video".$.outerHTML);
  5. const img = new Image();
  6. img.onload = () => console.log(img.$base64("image/png", 32).slice(0, 30));
  7. img.src = "/favicon.png";
  8. </script>
Live preview · @pardnchiu/renderjs@2.0.3
中文