From 679b56d59d36a712c8ff9d71c6ac84556afab0f6 Mon Sep 17 00:00:00 2001 From: Tamara Date: Thu, 13 Jul 2023 02:32:35 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BD=D0=B0=D1=80=D0=B5=D0=B7=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B2=D0=B8=D0=BA=D0=BE=D0=BD=D0=BE=D0=BA-18=D1=88?= =?UTF-8?q?=D1=82=D1=83=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/startPage/dropfavicon.tsx | 202 +++++++++++++++++++++++++--- 1 file changed, 181 insertions(+), 21 deletions(-) diff --git a/src/pages/startPage/dropfavicon.tsx b/src/pages/startPage/dropfavicon.tsx index 8aab2a74..b52dde93 100644 --- a/src/pages/startPage/dropfavicon.tsx +++ b/src/pages/startPage/dropfavicon.tsx @@ -14,30 +14,176 @@ interface Props { export default ({text, sx, heightImg, widthImg}: Props) => { const theme = useTheme(); // const callback = (newFileUri:any) => setData(URL.createObjectURL(newFileUri)); + const imageFavicon = [ + { + maxWidth: 16, + maxHeight: 16, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 32, + maxHeight: 32, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 48, + maxHeight: 48, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 76, + maxHeight: 76, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 96, + maxHeight: 96, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 120, + maxHeight: 120, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 128, + maxHeight: 128, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 144, + maxHeight: 144, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 152, + maxHeight: 152, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 167, + maxHeight: 167, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 180, + maxHeight: 180, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 192, + maxHeight: 192, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 196, + maxHeight: 196, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 228, + maxHeight: 288, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 256, + maxHeight: 256, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 300, + maxHeight: 300, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 384, + maxHeight: 384, + compressFormat: "PNG", + quality: 100, + rotation: 0 + }, + { + maxWidth: 512, + maxHeight: 512, + compressFormat: "PNG", + quality: 100, + rotation: 0 + } + ] const callback = (uri:any) => { var link = document.createElement('a'); link.href = uri; - link.download = 'Download.jpg'; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); + // link.download = 'Download.jpg'; + // document.body.appendChild(link); + // link.click(); + // document.body.removeChild(link); + console.log(link) }; - const resizeImage = (imageFile:any) => { - console.log(imageFile[0]) - try { - Resizer.imageFileResizer( - imageFile[0], - 150, - 150, - "JPEG", - 100, - 0, - callback, - ); - } catch (err) { - console.log(err); - } - } + + // imageFavicon.forEach((obj) => { + // try { + // Resizer.imageFileResizer( + // imageFile[0], + // obj.maxWidth, + // obj.maxHeight, + // obj.compressFormat, + // obj.quality, + // obj.rotation, + // callback, + // ); + // } catch (err) { + // console.log(err); + // } + // }) + + // const resizeImage = (imageFile:any) => { + // console.log(imageFile[0]) + // try { + // Resizer.imageFileResizer( + // imageFile[0], + // 150, + // 150, + // "PNG", + // 100, + // 0, + // callback, + // ); + // } catch (err) { + // console.log(err); + // } + // } const imgHC = (imgInp:any) => { @@ -45,7 +191,21 @@ export default ({text, sx, heightImg, widthImg}: Props) => { if (file.size < 5242880) { setData(URL.createObjectURL(file)) } else {enqueueSnackbar('Размер картинки слишком велик')} - resizeImage(imgInp.files) + imageFavicon.forEach(obj => { + try { + Resizer.imageFileResizer( + [file][0], + obj.maxWidth, + obj.maxHeight, + obj.compressFormat, + obj.quality, + obj.rotation, + callback, + ); + } catch (err) { + console.log(err); + } + }) }