0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 08:20:45 -05:00

🐛 Fix thumbnails being rendered with previous size

This commit is contained in:
Aitor 2023-05-24 12:40:28 +02:00 committed by Alonso Torres
parent fb3655506f
commit 48b0df8e75
3 changed files with 17 additions and 13 deletions

View file

@ -273,7 +273,7 @@
:response-type :blob
:method :get})
(rx/map :body)
(rx/map (fn [blob] (.createObjectURL js/URL blob)))))
(rx/map (fn [blob] (wapi/create-uri blob)))))
(defn- fetch-thumbnail-blobs
[file-id]

View file

@ -38,10 +38,20 @@
[value]))
(defn- create-svg-blob-uri-from
[fixed-width fixed-height rect node style-node]
[rect node style-node]
(let [{:keys [x y width height]} rect
viewbox (dm/str x " " y " " width " " height)
;; Calculate the fixed width and height
;; We don't want to generate thumbnails
;; bigger than 2000px
[fixed-width fixed-height]
(if (> width height)
[(mth/clamp width 250 2000)
(/ (* height (mth/clamp width 250 2000)) width)]
[(/ (* width (mth/clamp height 250 2000)) height)
(mth/clamp height 250 2000)])
;; This is way faster than creating a node
;; through the DOM API
svg-data
@ -53,8 +63,8 @@
(dom/node->xml node))
;; create SVG blob
blob (js/Blob. #js [svg-data] #js {:type "image/svg+xml;charset=utf-8"})
url (dm/str (.createObjectURL js/URL blob) "#svg")]
blob (wapi/create-blob svg-data "image/svg+xml;charset=utf-8")
url (dm/str (wapi/create-uri blob) "#svg")]
;; returns the url and the node
url))
@ -76,13 +86,6 @@
(gsh/selection-rect (concat [shape] all-children))
(-> shape :points gsh/points->selrect))
[fixed-width fixed-height]
(if (> width height)
[(mth/clamp width 250 2000)
(/ (* height (mth/clamp width 250 2000)) width)]
[(/ (* width (mth/clamp height 250 2000)) height)
(mth/clamp height 250 2000)])
svg-uri* (mf/use-state nil)
bitmap-uri* (mf/use-state nil)
observer* (mf/use-var nil)
@ -131,7 +134,7 @@
(if (dom/has-children? node)
;; The frame-content need to have children in order to generate the thumbnail
(let [style-node (dom/query (dm/str "#frame-container-" id " style"))
url (create-svg-blob-uri-from fixed-width fixed-height @shape-bb* node style-node)]
url (create-svg-blob-uri-from @shape-bb* node style-node)]
(reset! svg-uri* url))
;; Node not yet ready, we schedule a new generation

View file

@ -15,6 +15,7 @@
[app.main.render :as render]
[app.util.http :as http]
[app.util.time :as ts]
[app.util.webapi :as wapi]
[app.worker.impl :as impl]
[beicon.core :as rx]
[debug :refer [debug?]]
@ -143,7 +144,7 @@
(->> (.convertToBlob ^js canvas #js {:type "image/png"})
(p/fmap (fn [blob]
{:result (.createObjectURL js/URL blob)}))
{:result (wapi/create-uri blob)}))
(p/fnly (fn [_]
(log/debug :hint "generated thumbnail" :elapsed (dm/str (tp) "ms"))
(.close ^js ibpm))))))