diff --git a/other/wallpaper-samples/20211209_010332.heic b/other/wallpaper-samples/20211209_010332.heic new file mode 100644 index 000000000..eb3f8b5ab Binary files /dev/null and b/other/wallpaper-samples/20211209_010332.heic differ diff --git a/other/wallpaper-samples/20220101_155315.heic b/other/wallpaper-samples/20220101_155315.heic new file mode 100644 index 000000000..1c408e7d6 Binary files /dev/null and b/other/wallpaper-samples/20220101_155315.heic differ diff --git a/other/wallpaper-samples/20220105_130407.heic b/other/wallpaper-samples/20220105_130407.heic new file mode 100644 index 000000000..7d43ea587 Binary files /dev/null and b/other/wallpaper-samples/20220105_130407.heic differ diff --git a/other/wallpaper-samples/20220127_152742.heic b/other/wallpaper-samples/20220127_152742.heic new file mode 100644 index 000000000..468293a75 Binary files /dev/null and b/other/wallpaper-samples/20220127_152742.heic differ diff --git a/other/wallpaper-samples/20220207_141122.heic b/other/wallpaper-samples/20220207_141122.heic new file mode 100644 index 000000000..f760cb0c2 Binary files /dev/null and b/other/wallpaper-samples/20220207_141122.heic differ diff --git a/other/wallpaper-samples/20220208_145707.heic b/other/wallpaper-samples/20220208_145707.heic new file mode 100644 index 000000000..318fa12f4 Binary files /dev/null and b/other/wallpaper-samples/20220208_145707.heic differ diff --git a/other/wallpaper-samples/20220215_145915.heic b/other/wallpaper-samples/20220215_145915.heic new file mode 100644 index 000000000..49644e6e1 Binary files /dev/null and b/other/wallpaper-samples/20220215_145915.heic differ diff --git a/other/wallpaper-samples/20220215_160201.heic b/other/wallpaper-samples/20220215_160201.heic new file mode 100644 index 000000000..d5e401ebe Binary files /dev/null and b/other/wallpaper-samples/20220215_160201.heic differ diff --git a/other/wallpaper-samples/20220219_155700.heic b/other/wallpaper-samples/20220219_155700.heic new file mode 100644 index 000000000..8d70aa97e Binary files /dev/null and b/other/wallpaper-samples/20220219_155700.heic differ diff --git a/other/wallpaper-samples/20220223_164612.heic b/other/wallpaper-samples/20220223_164612.heic new file mode 100644 index 000000000..de6066ded Binary files /dev/null and b/other/wallpaper-samples/20220223_164612.heic differ diff --git a/other/wallpaper-samples/20220315_144126.heic b/other/wallpaper-samples/20220315_144126.heic new file mode 100644 index 000000000..35ffc75e8 Binary files /dev/null and b/other/wallpaper-samples/20220315_144126.heic differ diff --git a/other/wallpaper-samples/20220319_160701.heic b/other/wallpaper-samples/20220319_160701.heic new file mode 100644 index 000000000..5319b08ef Binary files /dev/null and b/other/wallpaper-samples/20220319_160701.heic differ diff --git a/other/wallpaper-samples/20220319_164131.heic b/other/wallpaper-samples/20220319_164131.heic new file mode 100644 index 000000000..6e56df7f4 Binary files /dev/null and b/other/wallpaper-samples/20220319_164131.heic differ diff --git a/other/wallpaper-samples/20220319_174200.heic b/other/wallpaper-samples/20220319_174200.heic new file mode 100644 index 000000000..4c3a2d7a9 Binary files /dev/null and b/other/wallpaper-samples/20220319_174200.heic differ diff --git a/other/wallpaper-samples/20220319_174757.heic b/other/wallpaper-samples/20220319_174757.heic new file mode 100644 index 000000000..9ab61f242 Binary files /dev/null and b/other/wallpaper-samples/20220319_174757.heic differ diff --git a/other/wallpaper-samples/20220322_154653.heic b/other/wallpaper-samples/20220322_154653.heic new file mode 100644 index 000000000..aa444a2c0 Binary files /dev/null and b/other/wallpaper-samples/20220322_154653.heic differ diff --git a/other/wallpaper-samples/20220322_163319.heic b/other/wallpaper-samples/20220322_163319.heic new file mode 100644 index 000000000..ac6f7a59e Binary files /dev/null and b/other/wallpaper-samples/20220322_163319.heic differ diff --git a/other/wallpaper-samples/20220326_142552.heic b/other/wallpaper-samples/20220326_142552.heic new file mode 100644 index 000000000..ecd097c04 Binary files /dev/null and b/other/wallpaper-samples/20220326_142552.heic differ diff --git a/other/wallpaper-samples/20220327_122308.heic b/other/wallpaper-samples/20220327_122308.heic new file mode 100644 index 000000000..2192f1500 Binary files /dev/null and b/other/wallpaper-samples/20220327_122308.heic differ diff --git a/other/wallpaper-samples/20220328_152716.heic b/other/wallpaper-samples/20220328_152716.heic new file mode 100644 index 000000000..9dd9aee4a Binary files /dev/null and b/other/wallpaper-samples/20220328_152716.heic differ diff --git a/other/wallpaper-samples/20220328_194840.heic b/other/wallpaper-samples/20220328_194840.heic new file mode 100644 index 000000000..8bba48894 Binary files /dev/null and b/other/wallpaper-samples/20220328_194840.heic differ diff --git a/other/wallpaper-samples/sample1.heif b/other/wallpaper-samples/sample1.heif new file mode 100644 index 000000000..7a68f35da Binary files /dev/null and b/other/wallpaper-samples/sample1.heif differ diff --git a/package-lock.json b/package-lock.json index 1e49413bf..0c75c537d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "everstorage": "1.13.0", "file-saver": "2.0.5", "formidable": "3.5.0", + "heic2any": "^0.0.4", "html-react-parser": "3.0.12", "isomorphic-fetch": "3.0.0", "jszip": "3.10.1", @@ -9489,6 +9490,11 @@ "he": "bin/he" } }, + "node_modules/heic2any": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/heic2any/-/heic2any-0.0.4.tgz", + "integrity": "sha512-3lLnZiDELfabVH87htnRolZ2iehX9zwpRyGNz22GKXIu0fznlblf0/ftppXKNqS26dqFSeqfIBhAmAj/uSp0cA==" + }, "node_modules/hex-rgb": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/hex-rgb/-/hex-rgb-4.3.0.tgz", @@ -24712,6 +24718,11 @@ "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==" }, + "heic2any": { + "version": "0.0.4", + "resolved": "https://registry.npmjs.org/heic2any/-/heic2any-0.0.4.tgz", + "integrity": "sha512-3lLnZiDELfabVH87htnRolZ2iehX9zwpRyGNz22GKXIu0fznlblf0/ftppXKNqS26dqFSeqfIBhAmAj/uSp0cA==" + }, "hex-rgb": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/hex-rgb/-/hex-rgb-4.3.0.tgz", diff --git a/package.json b/package.json index 4b49ae64c..2f2d082d6 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,7 @@ "everstorage": "1.13.0", "file-saver": "2.0.5", "formidable": "3.5.0", + "heic2any": "^0.0.4", "html-react-parser": "3.0.12", "isomorphic-fetch": "3.0.0", "jszip": "3.10.1", diff --git a/src/workers/createNewWallpaper.worker.ts b/src/workers/createNewWallpaper.worker.ts index 146405bf3..3e6b59c7a 100644 --- a/src/workers/createNewWallpaper.worker.ts +++ b/src/workers/createNewWallpaper.worker.ts @@ -1,3 +1,4 @@ +import heic2any from 'heic2any'; import spaceTrim from 'spacetrim'; import { COLORSTATS_DEFAULT_COMPUTE_IN_FRONTEND, @@ -19,6 +20,8 @@ import { resizeImageBlob } from '../utils/image/resizeImageBlob'; import { getSupabaseForWorker } from '../utils/supabase/getSupabaseForWorker'; import { string_wallpaper_id, uuid } from '../utils/typeAliases'; +heic2any; + export interface IMessage_CreateNewWallpaper_Request { type: 'CREATE_NEW_WALLPAPER_REQUEST'; author: uuid; @@ -76,6 +79,21 @@ async function createNewWallpaper( const { author, wallpaperImage: wallpaper } = options; const computeColorstats = COLORSTATS_DEFAULT_COMPUTE_IN_FRONTEND; + //=========================================================================== + //-------[ Convert + resize: ]--- + const jpegFile = await heic2any({ + // @see https://github.com/alexcorvi/heic2any/blob/master/docs/options.md + blob: heicFile, + toType: 'image/jpeg' /* <- TODO: Let user pick compression and type of conversion */, + quality: 0.85, + }); + const wallpaperResizedCanvas = await createOffscreenCanvas( + wallpaperOriginalBlob, + IMAGE_NATURAL_SIZE.scale(0.5) /* <- TODO: [🧔] This should be in config */, + ); + const wallpaperResizedBlob = await wallpaperResizedCanvas.convertToBlob(); + //-------[ /Convert + resize ]--- + //=========================================================================== //-------[ Image analysis and check: ]--- await onProgress({