mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Merge branch 'feat/image-converter' into chore/all-my-stuffs
# Conflicts: # package.json # pnpm-lock.yaml # src/tools/index.ts
This commit is contained in:
commit
d3eca6ff55
7 files changed
+215
No files matched your search
@@ -119,6 +119,7 @@
|
||||
"js-base64": "^3.7.7",
|
||||
"ical-generator": "^8.0.0",
|
||||
"ical.js": "^2.1.0",
|
||||
"image-in-browser": "^3.2.0",
|
||||
"js-base64": "^3.7.6",
|
||||
"image-in-browser": "^3.1.0",
|
||||
"js-base64": "^3.7.7",
|
||||
@@ -155,6 +156,9 @@
|
||||
"sql-formatter": "^13.0.0",
|
||||
"sshpk": "^1.18.0",
|
||||
"turndown": "^7.1.2",
|
||||
"roboto-base64": "^0.1.2",
|
||||
"sql-formatter": "^13.0.0",
|
||||
"svg2png-wasm": "^1.4.1",
|
||||
"ua-parser-js": "^1.0.35",
|
||||
"ulid": "^2.3.0",
|
||||
"unicode-emoji-json": "^0.4.0",
|
||||
@@ -166,6 +170,7 @@
|
||||
"vue-router": "^4.1.6",
|
||||
"vue-shadow-dom": "^4.2.0",
|
||||
"vue-tsc": "^1.8.1",
|
||||
"webp-converter-browser": "^1.0.4",
|
||||
"vuedraggable": "^4.1.0",
|
||||
"xml-formatter": "^3.3.2",
|
||||
"xml-js": "^1.6.11",
|
||||
|
||||
Generated
+23
@@ -314,6 +314,9 @@ dependencies:
|
||||
regex:
|
||||
specifier: ^4.3.3
|
||||
version: 4.4.0
|
||||
roboto-base64:
|
||||
specifier: ^0.1.2
|
||||
version: 0.1.2
|
||||
rtf-stream-parser:
|
||||
specifier: ^3.8.0
|
||||
version: 3.8.0
|
||||
@@ -326,6 +329,9 @@ dependencies:
|
||||
sshpk:
|
||||
specifier: ^1.18.0
|
||||
version: 1.18.0
|
||||
svg2png-wasm:
|
||||
specifier: ^1.4.1
|
||||
version: 1.4.1
|
||||
turndown:
|
||||
specifier: ^7.1.2
|
||||
version: 7.2.0
|
||||
@@ -365,6 +371,9 @@ dependencies:
|
||||
vuedraggable:
|
||||
specifier: ^4.1.0
|
||||
version: 4.1.0(vue@3.3.4)
|
||||
webp-converter-browser:
|
||||
specifier: ^1.0.4
|
||||
version: 1.0.4
|
||||
xml-formatter:
|
||||
specifier: ^3.3.2
|
||||
version: 3.3.2
|
||||
@@ -9699,6 +9708,10 @@ packages:
|
||||
inherits: 2.0.4
|
||||
dev: true
|
||||
|
||||
/roboto-base64@0.1.2:
|
||||
resolution: {integrity: sha512-vXOGVIresupkks/WVNy4upNA4OorZx6XbHJt5ZQaat1tHBdJxui3oI101n9XV9Yg6HWIQKeAGnQbJJaUa8mfvA==}
|
||||
dev: false
|
||||
|
||||
/rollup-plugin-terser@7.0.2(rollup@2.79.1):
|
||||
resolution: {integrity: sha512-w3iIaU4OxcF52UUXiZNsNeuXIMDvFrr+ZXK6bFZ0Q60qyVfq4uLptoS4bbq3paG3x216eQllFZX7zt6TIImguQ==}
|
||||
deprecated: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser
|
||||
@@ -10276,6 +10289,10 @@ packages:
|
||||
resolution: {integrity: sha512-ovssysQTa+luh7A5Weu3Rta6FJlFBBbInjOh722LIt6klpU2/HtdUbszju/G4devcvk8PGt7FCLv5wftu3THUA==}
|
||||
dev: true
|
||||
|
||||
/svg2png-wasm@1.4.1:
|
||||
resolution: {integrity: sha512-ZFy1NtwZVAsslaTQoI+/QqX2sg0vjmgJ/jGAuLZZvYcRlndI54hLPiwLC9JzXlFBerfxN5JiS7kpEUG0mrXS3Q==}
|
||||
dev: false
|
||||
|
||||
/svgo@3.0.2:
|
||||
resolution: {integrity: sha512-Z706C1U2pb1+JGP48fbazf3KxHrWOsLme6Rv7imFBn5EnuanDW1GPaA/P1/dvObE670JDePC3mnj0k0B7P0jjQ==}
|
||||
engines: {node: '>=14.0.0'}
|
||||
@@ -11431,6 +11448,12 @@ packages:
|
||||
engines: {node: '>=12'}
|
||||
dev: true
|
||||
|
||||
/webp-converter-browser@1.0.4:
|
||||
resolution: {integrity: sha512-ZkcrrM4TyxBI7mPmE4uG6PU2MF5YXhKTtvub/ll/4ZjXM7THcms0C0tA10CwnsrLzRBC+ry/sUzwpW6vdPzA8g==}
|
||||
dependencies:
|
||||
'@babel/runtime': 7.23.2
|
||||
dev: false
|
||||
|
||||
/webpack-sources@3.2.3:
|
||||
resolution: {integrity: sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==}
|
||||
engines: {node: '>=10.13.0'}
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,170 @@
|
||||
<script setup lang="ts">
|
||||
import { Base64 } from 'js-base64';
|
||||
import type { MemoryImage } from 'image-in-browser';
|
||||
import { decodeImage, encodeBmp, encodeGif, encodeIco, encodeJpg, encodePng, encodePvr, encodeTga, encodeTiff } from 'image-in-browser';
|
||||
import { arrayBufferToWebP } from 'webp-converter-browser';
|
||||
import { createSvg2png, initialize } from 'svg2png-wasm';
|
||||
import { normal as robotoBase64 } from 'roboto-base64';
|
||||
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
|
||||
import { useQueryParamOrStorage } from '@/composable/queryParams';
|
||||
|
||||
function readAsText(file: File) {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsText(file);
|
||||
reader.onload = () => resolve(reader.result?.toString() ?? '');
|
||||
reader.onerror = error => reject(error);
|
||||
});
|
||||
}
|
||||
|
||||
const status = ref<'idle' | 'done' | 'error' | 'processing'>('idle');
|
||||
const file = ref<File | null>(null);
|
||||
|
||||
const svgScale = ref(2);
|
||||
const base64OutputFile = ref('');
|
||||
const fileName = ref('');
|
||||
const fileExtension = ref('');
|
||||
const { download } = useDownloadFileFromBase64(
|
||||
{
|
||||
source: base64OutputFile,
|
||||
filename: fileName,
|
||||
extension: fileExtension,
|
||||
});
|
||||
|
||||
const outputQuality = useQueryParamOrStorage({ name: 'qual', storageName: 'imgconv:q', defaultValue: 0.95 });
|
||||
const outputFormats = {
|
||||
png: {
|
||||
mime: 'image/png',
|
||||
save: (image: MemoryImage) => encodePng({ image }),
|
||||
},
|
||||
jpg: {
|
||||
mime: 'image/jpeg',
|
||||
save: (image: MemoryImage) => encodeJpg({ image, quality: outputQuality.value }),
|
||||
},
|
||||
bmp: {
|
||||
mime: 'image/bmp',
|
||||
save: (image: MemoryImage) => encodeBmp({ image }),
|
||||
},
|
||||
gif: {
|
||||
mime: 'image/gif',
|
||||
save: (image: MemoryImage) => encodeGif({ image }),
|
||||
},
|
||||
ico: {
|
||||
mime: 'image/x-icon',
|
||||
save: (image: MemoryImage) => encodeIco({ image }),
|
||||
},
|
||||
tga: {
|
||||
mime: 'image/tga',
|
||||
save: (image: MemoryImage) => encodeTga({ image }),
|
||||
},
|
||||
pvr: {
|
||||
mime: 'image/pvr',
|
||||
save: (image: MemoryImage) => encodePvr({ image }),
|
||||
},
|
||||
tif: {
|
||||
mime: 'image/tif',
|
||||
save: (image: MemoryImage) => encodeTiff({ image }),
|
||||
},
|
||||
webp: {
|
||||
mime: 'image/webp',
|
||||
save: () => null,
|
||||
},
|
||||
};
|
||||
|
||||
const outputFormat = useQueryParamOrStorage({ name: 'fmt', storageName: 'imgconv:fmt', defaultValue: 'png' });
|
||||
const outputFormatHasQuality = computed(() => {
|
||||
return outputFormat.value === 'jpg';
|
||||
});
|
||||
|
||||
const svgWasmLoaded = ref(false);
|
||||
|
||||
async function onFileUploaded(uploadedFile: File) {
|
||||
const outputFormatValue = outputFormat.value;
|
||||
file.value = uploadedFile;
|
||||
let fileBuffer = new Uint8Array(await uploadedFile.arrayBuffer());
|
||||
|
||||
fileName.value = `${uploadedFile.name}`;
|
||||
status.value = 'processing';
|
||||
try {
|
||||
if (outputFormatValue === 'webp') {
|
||||
const encodedImage = await arrayBufferToWebP(fileBuffer);
|
||||
fileExtension.value = 'webp';
|
||||
base64OutputFile.value = `data:image/webp;base64,${Base64.fromUint8Array(new Uint8Array(await encodedImage.arrayBuffer()))}`;
|
||||
}
|
||||
else {
|
||||
if (uploadedFile.type === 'image/svg+xml') {
|
||||
if (!svgWasmLoaded.value) {
|
||||
await initialize(fetch('/svg2png_wasm_bg.wasm'));
|
||||
svgWasmLoaded.value = true;
|
||||
}
|
||||
const svg2png = createSvg2png({
|
||||
fonts: [Base64.toUint8Array(robotoBase64)],
|
||||
});
|
||||
fileBuffer = await svg2png(await readAsText(uploadedFile), { scale: svgScale.value });
|
||||
svg2png.dispose();
|
||||
}
|
||||
const decodedImage = decodeImage({
|
||||
data: fileBuffer,
|
||||
});
|
||||
|
||||
if (decodedImage == null) {
|
||||
throw new Error('Invalid Image file!');
|
||||
};
|
||||
|
||||
const outConfig = outputFormats[outputFormatValue as (keyof typeof outputFormats)];
|
||||
const encodedImage = outConfig.save(decodedImage);
|
||||
fileExtension.value = outputFormatValue;
|
||||
base64OutputFile.value = `data:${outConfig.mime};base64,${Base64.fromUint8Array(encodedImage!)}`;
|
||||
}
|
||||
status.value = 'done';
|
||||
|
||||
download();
|
||||
}
|
||||
catch (e) {
|
||||
status.value = 'error';
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div style="flex: 0 0 100%" mb-2>
|
||||
<div mx-auto max-w-600px>
|
||||
<c-file-upload
|
||||
title="Drag and drop an image file here, or click to select a file"
|
||||
accept="image/*"
|
||||
paste-image
|
||||
@file-upload="onFileUploaded"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<c-select
|
||||
v-model:value="outputFormat"
|
||||
label="Output format:"
|
||||
label-position="left"
|
||||
:options="Object.keys(outputFormats)"
|
||||
placeholder="Select output format"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<div mb-2 flex justify-center>
|
||||
<n-form-item v-if="outputFormatHasQuality" label="Output quality:" label-placement="left">
|
||||
<n-input-number v-model:value="outputQuality" :max="100" :min="0" w-full />
|
||||
</n-form-item>
|
||||
<n-form-item label="SVG scaling:" label-placement="left">
|
||||
<n-input-number v-model:value="svgScale" :min="0" />
|
||||
</n-form-item>
|
||||
</div>
|
||||
|
||||
<div mt-3 flex justify-center>
|
||||
<c-alert v-if="status === 'error'" type="error">
|
||||
An error occured processing {{ fileName }}
|
||||
</c-alert>
|
||||
<n-spin
|
||||
v-if="status === 'processing'"
|
||||
size="small"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { PictureInPicture } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Image Formats Converter',
|
||||
path: '/image-converter',
|
||||
description: 'Convert images from one format to another',
|
||||
keywords: ['image', 'bmp', 'gif', 'ico', 'jpg', 'png', 'tga', 'pvr', 'tiff', 'pnm', 'pbm', 'pgm', 'ppm', 'psd', 'webp', 'converter'],
|
||||
component: () => import('./image-converter.vue'),
|
||||
icon: PictureInPicture,
|
||||
createdAt: new Date('2024-08-15'),
|
||||
});
|
||||
@@ -0,0 +1,3 @@
|
||||
declare module 'roboto-base64' {
|
||||
export const normal: string;
|
||||
}
|
||||
@@ -13,6 +13,7 @@ import { tool as outlookParser } from './outlook-parser';
|
||||
import { tool as fileHasher } from './file-hasher';
|
||||
import { tool as hexFileConverter } from './hex-file-converter';
|
||||
import { tool as icalMerger } from './ical-merger';
|
||||
import { tool as imageConverter } from './image-converter';
|
||||
|
||||
import { tool as cssXpathConverter } from './css-xpath-converter';
|
||||
import { tool as cssSelectorsMemo } from './css-selectors-memo';
|
||||
@@ -207,6 +208,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
barcodeGenerator,
|
||||
heicConverter,
|
||||
icoConverter,
|
||||
imageConverter,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user