mirror of
https://github.com/penpot/penpot.git
synced 2025-06-03 00:31:40 +02:00
🐛 Improved resilience for thumbnail generation
This commit is contained in:
parent
baf3f7ea15
commit
9099403421
1 changed files with 14 additions and 8 deletions
|
@ -19,12 +19,17 @@
|
||||||
|
|
||||||
(defn- draw-thumbnail-canvas
|
(defn- draw-thumbnail-canvas
|
||||||
[canvas-node img-node]
|
[canvas-node img-node]
|
||||||
(let [canvas-context (.getContext canvas-node "2d")
|
(try
|
||||||
canvas-width (.-width canvas-node)
|
(when (and (some? canvas-node) (some? img-node))
|
||||||
canvas-height (.-height canvas-node)]
|
(let [canvas-context (.getContext canvas-node "2d")
|
||||||
(.clearRect canvas-context 0 0 canvas-width canvas-height)
|
canvas-width (.-width canvas-node)
|
||||||
(.drawImage canvas-context img-node 0 0 canvas-width canvas-height)
|
canvas-height (.-height canvas-node)]
|
||||||
(.toDataURL canvas-node "image/png")))
|
(.clearRect canvas-context 0 0 canvas-width canvas-height)
|
||||||
|
(.drawImage canvas-context img-node 0 0 canvas-width canvas-height)
|
||||||
|
(.toDataURL canvas-node "image/png")))
|
||||||
|
(catch :default err
|
||||||
|
(.error js/console err)
|
||||||
|
nil)))
|
||||||
|
|
||||||
(defn use-render-thumbnail
|
(defn use-render-thumbnail
|
||||||
"Hook that will create the thumbnail thata"
|
"Hook that will create the thumbnail thata"
|
||||||
|
@ -54,8 +59,9 @@
|
||||||
#(let [canvas-node (mf/ref-val frame-canvas-ref)
|
#(let [canvas-node (mf/ref-val frame-canvas-ref)
|
||||||
img-node (mf/ref-val frame-image-ref)
|
img-node (mf/ref-val frame-image-ref)
|
||||||
thumb-data (draw-thumbnail-canvas canvas-node img-node)]
|
thumb-data (draw-thumbnail-canvas canvas-node img-node)]
|
||||||
(st/emit! (dw/update-thumbnail id thumb-data))
|
(when (some? thumb-data)
|
||||||
(reset! image-url nil)))))
|
(st/emit! (dw/update-thumbnail id thumb-data))
|
||||||
|
(reset! image-url nil))))))
|
||||||
|
|
||||||
on-update-frame
|
on-update-frame
|
||||||
(fn []
|
(fn []
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue