0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-03 04:49:03 -05:00

Start use jpeg instead of webp for thumbnails.

Because Safari still does not supports WEBP :(
This commit is contained in:
Andrey Antukh 2020-06-04 15:50:59 +02:00
parent c6581a91e4
commit e0a567551f
3 changed files with 14 additions and 20 deletions

View file

@ -2,7 +2,10 @@
;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; License, v. 2.0. If a copy of the MPL was not distributed with this
;; file, You can obtain one at http://mozilla.org/MPL/2.0/. ;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;; ;;
;; Copyright (c) 2016-2017 Andrey Antukh <niwi@niwi.nz> ;; This Source Code Form is "Incompatible With Secondary Licenses", as
;; defined by the Mozilla Public License, v. 2.0.
;;
;; Copyright (c) 2020 UXBOX Labs SL
(ns uxbox.images (ns uxbox.images
"Image postprocessing." "Image postprocessing."
@ -62,18 +65,10 @@
tmp (fs/create-tempfile :suffix ext) tmp (fs/create-tempfile :suffix ext)
opr (doto (IMOperation.) opr (doto (IMOperation.)
(.addImage) (.addImage)
(.autoOrient) (.autoOrient)
(.strip) (.strip)
(.thumbnail (int width) (int height) ">") (.thumbnail (int width) (int height) ">")
(.quality (double quality)) (.quality (double quality))
;; (.autoOrient)
;; (.strip)
;; (.thumbnail (int width) (int height) "^")
;; (.gravity "center")
;; (.extent (int width) (int height))
;; (.quality (double quality))
(.addImage))] (.addImage))]
(doto (ConvertCmd.) (doto (ConvertCmd.)
(.run opr (into-array (map str [input tmp])))) (.run opr (into-array (map str [input tmp]))))
@ -81,7 +76,7 @@
(fs/delete tmp) (fs/delete tmp)
(ByteArrayInputStream. thumbnail-data))))) (ByteArrayInputStream. thumbnail-data)))))
(defn generate-thumbnail2 (defn generate-profile-thumbnail
([input] (generate-thumbnail input nil)) ([input] (generate-thumbnail input nil))
([input {:keys [quality format width height] ([input {:keys [quality format width height]
:or {format "jpeg" :or {format "jpeg"

View file

@ -5,23 +5,22 @@
;; This Source Code Form is "Incompatible With Secondary Licenses", as ;; This Source Code Form is "Incompatible With Secondary Licenses", as
;; defined by the Mozilla Public License, v. 2.0. ;; defined by the Mozilla Public License, v. 2.0.
;; ;;
;; Copyright (c) 2019-2020 Andrey Antukh <niwi@niwi.nz> ;; Copyright (c) 2020 UXBOX Labs SL
(ns uxbox.services.mutations.images (ns uxbox.services.mutations.images
(:require (:require
[clojure.spec.alpha :as s] [clojure.spec.alpha :as s]
[datoteka.core :as fs] [datoteka.core :as fs]
[promesa.core :as p]
[uxbox.common.exceptions :as ex] [uxbox.common.exceptions :as ex]
[uxbox.common.spec :as us] [uxbox.common.spec :as us]
[uxbox.common.uuid :as uuid]
[uxbox.config :as cfg] [uxbox.config :as cfg]
[uxbox.db :as db] [uxbox.db :as db]
[uxbox.media :as media]
[uxbox.images :as images] [uxbox.images :as images]
[uxbox.tasks :as tasks] [uxbox.media :as media]
[uxbox.services.queries.teams :as teams]
[uxbox.services.mutations :as sm] [uxbox.services.mutations :as sm]
[uxbox.common.uuid :as uuid] [uxbox.services.queries.teams :as teams]
[uxbox.tasks :as tasks]
[uxbox.util.storage :as ust] [uxbox.util.storage :as ust]
[uxbox.util.time :as dt])) [uxbox.util.time :as dt]))
@ -29,7 +28,7 @@
{:width 800 {:width 800
:height 800 :height 800
:quality 85 :quality 85
:format "webp"}) :format "jpeg"})
(s/def ::id ::us/uuid) (s/def ::id ::us/uuid)
(s/def ::name ::us/string) (s/def ::name ::us/string)

View file

@ -294,12 +294,12 @@
thumb-opts {:width 256 thumb-opts {:width 256
:height 256 :height 256
:quality 75 :quality 75
:format "webp"} :format "jpeg"}
prefix (-> (sodi.prng/random-bytes 8) prefix (-> (sodi.prng/random-bytes 8)
(sodi.util/bytes->b64s)) (sodi.util/bytes->b64s))
name (str prefix ".webp") name (str prefix ".jpg")
path (fs/path (:tempfile file)) path (fs/path (:tempfile file))
photo (images/generate-thumbnail2 path thumb-opts)] photo (images/generate-profile-thumbnail path thumb-opts)]
(ust/save! media/media-storage name photo))) (ust/save! media/media-storage name photo)))
(defn- update-profile-photo (defn- update-profile-photo