-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
643c1e2
commit 3941129
Showing
5 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<script setup lang="ts"> | ||
import axios from "axios"; | ||
import { selectFile } from "/@/lib/file/selectFile"; | ||
import { Message } from "@arco-design/web-vue"; | ||
import { IconLoading } from "@arco-design/web-vue/es/icon"; | ||
import ImageResize from "image-resize"; | ||
const file = ref<File>(); | ||
const apiKey = import.meta.env.VITE_TINIFY_API_KEY; | ||
const imgUrl = computed(() => file.value && URL.createObjectURL(file.value)); | ||
const output = ref<any>({}); | ||
const imgSrc = ref<any>(""); | ||
const errorMessage = ref(""); | ||
const loading = ref(false); | ||
const imageResize = new ImageResize(); | ||
async function onUpload() { | ||
file.value = await selectFile("image"); | ||
} | ||
async function onZip() { | ||
try { | ||
let res = await imageResize.play(file.value!); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
function onDownload() { | ||
if (!imgSrc.value) return; | ||
const downloadLink = document.createElement("a"); | ||
downloadLink.href = imgSrc.value; | ||
downloadLink.setAttribute("download", file.value?.name!); | ||
downloadLink.click(); | ||
} | ||
function bytesToKB(bytes?: number) { | ||
return ((bytes || 0) / 1024).toFixed(2) + " kb"; | ||
} | ||
</script> | ||
|
||
<template> | ||
<a-space> | ||
<a-button @click="onUpload">上传图片</a-button> | ||
<a-button v-if="imgUrl" @click="onZip">压缩图片</a-button> | ||
<a-button v-if="imgSrc" @click="onDownload">下载</a-button> | ||
</a-space> | ||
|
||
<div flex mt-20 border-1 h-500> | ||
<div w-45vw border-r-1 p-20> | ||
<div v-if="imgUrl"> | ||
<div pb-10 font-400 fs-20> | ||
<span>name: </span> | ||
<span>{{ file?.name }}</span> | ||
</div> | ||
<div pb-20 font-400 fs-20> | ||
<span>size: </span> | ||
<span>{{ bytesToKB(file?.size) }}</span> | ||
</div> | ||
<img max-w-full max-h-460 :src="imgUrl" alt="" /> | ||
</div> | ||
</div> | ||
<div flex-1 p-20> | ||
<div v-if="loading" w-full h-full flex justify-center items-center> | ||
<IconLoading size="50" /> | ||
</div> | ||
<div v-if="imgSrc || errorMessage"> | ||
<div pb-10 font-400 fs-20> | ||
<span>name: </span> | ||
<span>{{ file?.name }}</span> | ||
</div> | ||
<div pb-20 font-400 fs-20> | ||
<span>size: </span> | ||
<span>{{ bytesToKB(output?.size) }}</span> | ||
</div> | ||
<img v-if="imgSrc" max-w-full max-h-460 :src="imgSrc" alt="" /> | ||
<span v-else>{{ errorMessage }}</span> | ||
</div> | ||
</div> | ||
</div> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters