mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-21 07:16:15 -04:00
Merge 8eb9239279
into 07eea0f484
This commit is contained in:
commit
c0f557cbbb
9 changed files with 6561 additions and 7960 deletions
9
components.d.ts
vendored
9
components.d.ts
vendored
|
@ -101,6 +101,7 @@ declare module '@vue/runtime-core' {
|
||||||
IconMdiSearch: typeof import('~icons/mdi/search')['default']
|
IconMdiSearch: typeof import('~icons/mdi/search')['default']
|
||||||
IconMdiTranslate: typeof import('~icons/mdi/translate')['default']
|
IconMdiTranslate: typeof import('~icons/mdi/translate')['default']
|
||||||
IconMdiTriangleDown: typeof import('~icons/mdi/triangle-down')['default']
|
IconMdiTriangleDown: typeof import('~icons/mdi/triangle-down')['default']
|
||||||
|
ImageConverter: typeof import('./src/tools/image-converter/image-converter.vue')['default']
|
||||||
InputCopyable: typeof import('./src/components/InputCopyable.vue')['default']
|
InputCopyable: typeof import('./src/components/InputCopyable.vue')['default']
|
||||||
IntegerBaseConverter: typeof import('./src/tools/integer-base-converter/integer-base-converter.vue')['default']
|
IntegerBaseConverter: typeof import('./src/tools/integer-base-converter/integer-base-converter.vue')['default']
|
||||||
Ipv4AddressConverter: typeof import('./src/tools/ipv4-address-converter/ipv4-address-converter.vue')['default']
|
Ipv4AddressConverter: typeof import('./src/tools/ipv4-address-converter/ipv4-address-converter.vue')['default']
|
||||||
|
@ -135,14 +136,18 @@ declare module '@vue/runtime-core' {
|
||||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||||
NDivider: typeof import('naive-ui')['NDivider']
|
NDivider: typeof import('naive-ui')['NDivider']
|
||||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||||
|
NFormItem: typeof import('naive-ui')['NFormItem']
|
||||||
NH1: typeof import('naive-ui')['NH1']
|
NH1: typeof import('naive-ui')['NH1']
|
||||||
NH3: typeof import('naive-ui')['NH3']
|
NH3: typeof import('naive-ui')['NH3']
|
||||||
NIcon: typeof import('naive-ui')['NIcon']
|
NIcon: typeof import('naive-ui')['NIcon']
|
||||||
|
NInputNumber: typeof import('naive-ui')['NInputNumber']
|
||||||
NLayout: typeof import('naive-ui')['NLayout']
|
NLayout: typeof import('naive-ui')['NLayout']
|
||||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||||
NMenu: typeof import('naive-ui')['NMenu']
|
NMenu: typeof import('naive-ui')['NMenu']
|
||||||
NSpace: typeof import('naive-ui')['NSpace']
|
NProgress: typeof import('naive-ui')['NProgress']
|
||||||
NTable: typeof import('naive-ui')['NTable']
|
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||||
|
NSpin: typeof import('naive-ui')['NSpin']
|
||||||
|
NSwitch: typeof import('naive-ui')['NSwitch']
|
||||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||||
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
|
OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default']
|
||||||
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
|
PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default']
|
||||||
|
|
|
@ -70,6 +70,7 @@
|
||||||
"highlight.js": "^11.7.0",
|
"highlight.js": "^11.7.0",
|
||||||
"iarna-toml-esm": "^3.0.5",
|
"iarna-toml-esm": "^3.0.5",
|
||||||
"ibantools": "^4.3.3",
|
"ibantools": "^4.3.3",
|
||||||
|
"image-in-browser": "^3.2.0",
|
||||||
"js-base64": "^3.7.6",
|
"js-base64": "^3.7.6",
|
||||||
"json5": "^2.2.3",
|
"json5": "^2.2.3",
|
||||||
"jwt-decode": "^3.1.2",
|
"jwt-decode": "^3.1.2",
|
||||||
|
@ -89,7 +90,9 @@
|
||||||
"plausible-tracker": "^0.3.8",
|
"plausible-tracker": "^0.3.8",
|
||||||
"qrcode": "^1.5.1",
|
"qrcode": "^1.5.1",
|
||||||
"randexp": "^0.5.3",
|
"randexp": "^0.5.3",
|
||||||
|
"roboto-base64": "^0.1.2",
|
||||||
"sql-formatter": "^13.0.0",
|
"sql-formatter": "^13.0.0",
|
||||||
|
"svg2png-wasm": "^1.4.1",
|
||||||
"ua-parser-js": "^1.0.35",
|
"ua-parser-js": "^1.0.35",
|
||||||
"ulid": "^2.3.0",
|
"ulid": "^2.3.0",
|
||||||
"unicode-emoji-json": "^0.4.0",
|
"unicode-emoji-json": "^0.4.0",
|
||||||
|
@ -100,6 +103,7 @@
|
||||||
"vue-router": "^4.1.6",
|
"vue-router": "^4.1.6",
|
||||||
"vue-shadow-dom": "^4.2.0",
|
"vue-shadow-dom": "^4.2.0",
|
||||||
"vue-tsc": "^1.8.1",
|
"vue-tsc": "^1.8.1",
|
||||||
|
"webp-converter-browser": "^1.0.4",
|
||||||
"vuedraggable": "^4.1.0",
|
"vuedraggable": "^4.1.0",
|
||||||
"xml-formatter": "^3.3.2",
|
"xml-formatter": "^3.3.2",
|
||||||
"xml-js": "^1.6.11",
|
"xml-js": "^1.6.11",
|
||||||
|
|
14276
pnpm-lock.yaml
generated
14276
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load diff
BIN
public/svg2png_wasm_bg.wasm
Normal file
BIN
public/svg2png_wasm_bg.wasm
Normal file
Binary file not shown.
|
@ -1,6 +1,7 @@
|
||||||
import { extension as getExtensionFromMimeType, extension as getMimeTypeFromExtension } from 'mime-types';
|
import { extension as getExtensionFromMimeType, extension as getMimeTypeFromExtension } from 'mime-types';
|
||||||
import type { Ref } from 'vue';
|
import type { MaybeRef, Ref } from 'vue';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { get } from '@vueuse/core';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
getMimeTypeFromBase64,
|
getMimeTypeFromBase64,
|
||||||
|
@ -75,21 +76,11 @@ function downloadFromBase64({ sourceValue, filename, extension, fileMimeType }:
|
||||||
}
|
}
|
||||||
|
|
||||||
function useDownloadFileFromBase64(
|
function useDownloadFileFromBase64(
|
||||||
{ source, filename, extension, fileMimeType }:
|
|
||||||
{ source: Ref<string>; filename?: string; extension?: string; fileMimeType?: string }) {
|
|
||||||
return {
|
|
||||||
download() {
|
|
||||||
downloadFromBase64({ sourceValue: source.value, filename, extension, fileMimeType });
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function useDownloadFileFromBase64Refs(
|
|
||||||
{ source, filename, extension }:
|
{ source, filename, extension }:
|
||||||
{ source: Ref<string>; filename?: Ref<string>; extension?: Ref<string> }) {
|
{ source: MaybeRef<string>; filename?: MaybeRef<string>; extension?: MaybeRef<string> }) {
|
||||||
return {
|
return {
|
||||||
download() {
|
download() {
|
||||||
downloadFromBase64({ sourceValue: source.value, filename: filename?.value, extension: extension?.value });
|
downloadFromBase64({ sourceValue: get(source), filename: get(filename), extension: get(extension) });
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -116,3 +107,13 @@ function previewImageFromBase64(base64String: string): HTMLImageElement {
|
||||||
|
|
||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function useDownloadFileFromBase64Refs(
|
||||||
|
{ source, filename, extension }:
|
||||||
|
{ source: Ref<string>; filename?: Ref<string>; extension?: Ref<string> }) {
|
||||||
|
return {
|
||||||
|
download() {
|
||||||
|
downloadFromBase64({ sourceValue: source.value, filename: filename?.value, extension: extension?.value });
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
181
src/tools/image-converter/image-converter.vue
Normal file
181
src/tools/image-converter/image-converter.vue
Normal file
|
@ -0,0 +1,181 @@
|
||||||
|
<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 onFilesUploaded(uploadedFiles: File[]) {
|
||||||
|
for (const file of uploadedFiles) {
|
||||||
|
await onFileUploaded(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function onFileUploaded(uploadedFile: File) {
|
||||||
|
const outputFormatValue = outputFormat.value;
|
||||||
|
file.value = uploadedFile;
|
||||||
|
let fileBuffer = new Uint8Array(await uploadedFile.arrayBuffer());
|
||||||
|
|
||||||
|
fileName.value = uploadedFile.name.replace(/\.\w+$/, '');
|
||||||
|
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>
|
||||||
|
<h4>First, select output options:</h4>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<h4>Then, drag and drop your images below and they will be converted and downloaded immediately:</h4>
|
||||||
|
|
||||||
|
<div style="flex: 0 0 100%" mb-2>
|
||||||
|
<div mx-auto max-w-600px>
|
||||||
|
<c-file-upload
|
||||||
|
title="Drag and drop images files here, or click to select some files"
|
||||||
|
accept="image/*"
|
||||||
|
paste-image
|
||||||
|
multiple
|
||||||
|
@file-upload="onFileUploaded"
|
||||||
|
@files-upload="onFilesUploaded"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</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>
|
12
src/tools/image-converter/index.ts
Normal file
12
src/tools/image-converter/index.ts
Normal file
|
@ -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'),
|
||||||
|
});
|
3
src/tools/image-converter/roboto-base64.d.ts
vendored
Normal file
3
src/tools/image-converter/roboto-base64.d.ts
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
declare module 'roboto-base64' {
|
||||||
|
export const normal: string;
|
||||||
|
}
|
|
@ -2,6 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
|
||||||
import { tool as base64StringConverter } from './base64-string-converter';
|
import { tool as base64StringConverter } from './base64-string-converter';
|
||||||
import { tool as basicAuthGenerator } from './basic-auth-generator';
|
import { tool as basicAuthGenerator } from './basic-auth-generator';
|
||||||
import { tool as emailNormalizer } from './email-normalizer';
|
import { tool as emailNormalizer } from './email-normalizer';
|
||||||
|
import { tool as imageConverter } from './image-converter';
|
||||||
|
|
||||||
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
import { tool as asciiTextDrawer } from './ascii-text-drawer';
|
||||||
|
|
||||||
|
@ -141,7 +142,13 @@ export const toolsByCategory: ToolCategory[] = [
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Images and videos',
|
name: 'Images and videos',
|
||||||
components: [qrCodeGenerator, wifiQrCodeGenerator, svgPlaceholderGenerator, cameraRecorder],
|
components: [
|
||||||
|
qrCodeGenerator,
|
||||||
|
wifiQrCodeGenerator,
|
||||||
|
svgPlaceholderGenerator,
|
||||||
|
cameraRecorder,
|
||||||
|
imageConverter,
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Development',
|
name: 'Development',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue