ricecooker icon indicating copy to clipboard operation
ricecooker copied to clipboard

Better HTML5Zip thumbnail generation

Open ivanistheone opened this issue 6 years ago • 1 comments

The studio code has a much better way to generate thumbnails from zip files with web content: load the index.html in a headless browser and take a screenshot. See https://github.com/learningequality/studio/blob/f57e27a8898faecd99f4d4d97109cb50eab7e74a/contentcuration/contentcuration/utils/files.py#L342-L407

We should use this approach for create_image_from_zip, but not implemented with PhantomJS.

Waiting on https://github.com/learningequality/ricecooker/issues/176 to be fixed first so we can use the same tooling.

ivanistheone avatar Feb 19 '20 18:02 ivanistheone

Hi @ivanistheone We can improve HTML5 ZIP thumbnail generation by replacing PhantomJS with a headless browser like Playwright. The approach would be: Extract the ZIP file Locate index.html Open it using Playwright (file:// URL) Capture a screenshot and use it as the thumbnail

srushtikaware avatar Mar 18 '26 15:03 srushtikaware

Triage: blocked on a premise mismatch with #691

This issue asks to render an archive's entry point and capture a viewport screenshot, reusing "the headless Chromium capability from #691." On investigation, #691 (merged as PR #697) doesn't provide a screenshot primitive:

  • What #691 actually shipped is ricecooker/utils/singlefile.py::render_page(url, output_dir) — a wrapper around single-file-cli that saves a URL into a self-contained HTML file. single-file-cli's job is HTML page-archiving, not image capture; it emits an index.html, never a PNG.
  • There is no screenshot code anywhere on main, and render_page exposes no reusable Chromium binary path (browser_executable_path is an optional caller-supplied arg; it otherwise defers to single-file's own resolution).

So AC "No browser dependency beyond #691's headless Chromium is added" can't be met by reusing render_page as-is, and #691 hands us no Chromium handle to drive a screenshot ourselves.

Which direction do you want?

  1. Drive Chromium directly for the screenshot — resolve a chromium/chrome binary (from PATH, or single-file's bundled one) and run --headless --screenshot=... --window-size=... on the file:// entry point. Reuses the environmental Chromium #691 implies, but is new code, not a reuse of #691's API, and needs a defined Chromium-detection/feature-gate story.
  2. Add Playwright (as suggested above) purely for the render-and-screenshot path — cleanest API, but adds a browser dependency, which the current AC forbids.
  3. Extend #691 first to expose a screenshot helper (and a discoverable Chromium path), then build #335 on top.

Option 1 seems closest to intent but conflicts with a literal reading of the "reuse #691" framing and the detection is unspecified. Could you confirm the intended mechanism (and whether the "no new browser dependency" AC still holds) before implementation?

rtibblesbot avatar Jul 24 '26 04:07 rtibblesbot

I think option 1 seems simplest, and doesn't add a new dependency.

rtibbles avatar Jul 24 '26 05:07 rtibbles

Plan: Generate HTML5-zip and KPUB thumbnails by rendering the archive's entry point in a headless Chromium and screenshotting it, falling back to the biggest-image heuristic when Chromium is absent.

  • [ ] HTML entry-point resolver in utils/zip.py
  • [ ] Chromium detection + render-and-screenshot in utils/images.py
  • [ ] Wire render + Chromium-absent fallback into ExtractedHTMLZipThumbnailFile
  • [ ] KPUB thumbnail wiring

@rtibblesbot's comments are generated by an LLM, and should be evaluated accordingly

How was this generated?
  • Implemented code following the pre-approved plan using test-driven development (red-green-refactor)
  • Ran the project's full test suite and linter before committing
  • For UI changes: captured live screenshots to verify rendering
  • For backend changes: verified with example API/CLI output

rtibblesbot avatar Jul 24 '26 05:07 rtibblesbot

The bot has been waiting for a response for 2 hour(s). It will resume automatically when someone replies.

rtibblesbot avatar Jul 24 '26 08:07 rtibblesbot