mirror of
https://github.com/penpot/penpot.git
synced 2026-11-16 15:11:17 +00:00
🐛 Fix blurry file thumbnails rendered with render-wasm (#13026)
The wasm path drew file thumbnails on a 252px wide canvas, wrapped the PNG in an SVG and sent it to the rasterizer, which scaled it up to its default 300px width. The result was blurry on the dashboard on high-DPI screens and in the link preview card. Render the wasm thumbnail at 600px wide, twice the old size, and upload the canvas PNG as is, without the rasterizer round trip. The SVG render path keeps its current size. Closes #13025 AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
99497d3b7c
commit
b0dbbe8285
@ -50,6 +50,10 @@
|
||||
|
||||
(def thumbnail-width 252)
|
||||
|
||||
;; Larger than the grid card: the image is also the link preview card
|
||||
;; and has to stay sharp on high-DPI screens.
|
||||
(def ^:private wasm-thumbnail-width 600)
|
||||
|
||||
;; --- Grid Item Thumbnail
|
||||
|
||||
(defn- persist-thumbnail
|
||||
@ -58,30 +62,42 @@
|
||||
(->> (rp/cmd! :create-file-thumbnail params)
|
||||
(rx/map :id))))
|
||||
|
||||
(defn- render-thumbnail-with-wasm
|
||||
"Returns a stream with the PNG blob of the file thumbnail."
|
||||
[file-id revn]
|
||||
(->> (mw/ask! {:cmd :thumbnails/generate-for-file-wasm
|
||||
:revn revn
|
||||
:file-id file-id
|
||||
:width wasm-thumbnail-width})
|
||||
(rx/map :blob)))
|
||||
|
||||
(defn- render-thumbnail-with-svg
|
||||
"Returns a stream with the PNG blob of the file thumbnail."
|
||||
[file-id revn]
|
||||
(->> (mw/ask! {:cmd :thumbnails/generate-for-file
|
||||
:revn revn
|
||||
:file-id file-id
|
||||
:width thumbnail-width})
|
||||
(rx/mapcat
|
||||
(fn [{:keys [fonts] :as result}]
|
||||
(->> (fonts/render-font-styles fonts)
|
||||
(rx/map (fn [styles]
|
||||
(-> result
|
||||
(assoc :styles styles
|
||||
:width thumbnail-width)))))))
|
||||
(rx/mapcat thr/render)))
|
||||
|
||||
(defn render-thumbnail
|
||||
"Returns a stream with the PNG blob of the file thumbnail."
|
||||
[file-id revn]
|
||||
(if (features/active-feature? @st/state "render-wasm/v1")
|
||||
(mw/ask! {:cmd :thumbnails/generate-for-file-wasm
|
||||
:revn revn
|
||||
:file-id file-id
|
||||
:width thumbnail-width})
|
||||
(->> (mw/ask! {:cmd :thumbnails/generate-for-file
|
||||
:revn revn
|
||||
:file-id file-id
|
||||
:width thumbnail-width})
|
||||
(rx/mapcat
|
||||
(fn [{:keys [fonts] :as result}]
|
||||
(->> (fonts/render-font-styles fonts)
|
||||
(rx/map (fn [styles]
|
||||
(-> result
|
||||
(assoc :styles styles
|
||||
:width thumbnail-width))))))))))
|
||||
(render-thumbnail-with-wasm file-id revn)
|
||||
(render-thumbnail-with-svg file-id revn)))
|
||||
|
||||
(defn- ask-for-thumbnail
|
||||
"Creates some hooks to handle the files thumbnails cache"
|
||||
[file-id revn]
|
||||
(->> (render-thumbnail file-id revn)
|
||||
(rx/mapcat thr/render)
|
||||
(rx/mapcat (partial persist-thumbnail file-id revn))))
|
||||
|
||||
(mf/defc grid-item-thumbnail*
|
||||
|
||||
@ -7,7 +7,6 @@
|
||||
(ns app.worker.thumbnails
|
||||
(:require
|
||||
["react-dom/server" :as rds]
|
||||
[app.common.data.macros :as dm]
|
||||
[app.common.geom.rect :as grc]
|
||||
[app.common.geom.shapes.bounds :as gsb]
|
||||
[app.common.logging :as log]
|
||||
@ -107,37 +106,6 @@
|
||||
;; WASM RENDERING
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(mf/defc svg-wrapper*
|
||||
{::mf/private true}
|
||||
[{:keys [uri background width height]}]
|
||||
[:svg {:version "1.1"
|
||||
:xmlns "http://www.w3.org/2000/svg"
|
||||
:xmlnsXlink "http://www.w3.org/1999/xlink"
|
||||
|
||||
:style {:width "100%"
|
||||
:height "100%"
|
||||
:background background}
|
||||
:fill "none"
|
||||
:viewBox (dm/str "0 0 " width " " height)}
|
||||
[:image {:xlinkHref uri
|
||||
:width width
|
||||
:height height}]])
|
||||
|
||||
(defn- blob->uri
|
||||
[blob]
|
||||
(.readAsDataURL (js/FileReaderSync.) blob))
|
||||
|
||||
(defn- render-canvas-blob
|
||||
[canvas width height background]
|
||||
(->> (.convertToBlob ^js canvas)
|
||||
(p/fmap (fn [blob]
|
||||
(rds/renderToStaticMarkup
|
||||
(mf/element svg-wrapper*
|
||||
#js {:uri (blob->uri blob)
|
||||
:width width
|
||||
:height height
|
||||
:background background}))))))
|
||||
|
||||
(defn- render-thumbnail-with-wasm
|
||||
[{:keys [file-id revn width] :as _message}]
|
||||
(->> (rx/from @wwasm/module)
|
||||
@ -170,13 +138,13 @@
|
||||
(wasm.api/render-sync-shape (:id frame))
|
||||
(wasm.api/render-sync))
|
||||
|
||||
(->> (render-canvas-blob canvas width height bgcolor)
|
||||
(p/fnly (fn [data cause]
|
||||
(->> (.convertToBlob ^js canvas #js {:type "image/png"})
|
||||
(p/fnly (fn [blob cause]
|
||||
(wasm.api/clear-canvas)
|
||||
(if cause
|
||||
(rx/error! subs cause)
|
||||
(rx/push! subs
|
||||
{:data data
|
||||
{:blob blob
|
||||
:file-id file-id
|
||||
:revn revn}))
|
||||
(rx/end! subs)))))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user