mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-27 07:58:54 +03:00
Merge branch 'feat/ico-png-converter' into chore/all-my-stuffs
# Conflicts: # components.d.ts # pnpm-lock.yaml # src/tools/index.ts
This commit is contained in:
commit
8361798481
6 files changed
+182
-3
No files matched your search
@@ -120,6 +120,8 @@
|
|||||||
"ical-generator": "^8.0.0",
|
"ical-generator": "^8.0.0",
|
||||||
"ical.js": "^2.1.0",
|
"ical.js": "^2.1.0",
|
||||||
"js-base64": "^3.7.6",
|
"js-base64": "^3.7.6",
|
||||||
|
"image-in-browser": "^3.1.0",
|
||||||
|
"js-base64": "^3.7.7",
|
||||||
"json5": "^2.2.3",
|
"json5": "^2.2.3",
|
||||||
"jwt-decode": "^3.1.2",
|
"jwt-decode": "^3.1.2",
|
||||||
"libphonenumber-js": "^1.10.28",
|
"libphonenumber-js": "^1.10.28",
|
||||||
|
|||||||
Generated
+8
-1
@@ -221,11 +221,14 @@ dependencies:
|
|||||||
iconv-lite:
|
iconv-lite:
|
||||||
specifier: ^0.6.3
|
specifier: ^0.6.3
|
||||||
version: 0.6.3
|
version: 0.6.3
|
||||||
|
image-in-browser:
|
||||||
|
specifier: ^3.1.0
|
||||||
|
version: 3.2.1
|
||||||
iso-639-1:
|
iso-639-1:
|
||||||
specifier: ^3.1.3
|
specifier: ^3.1.3
|
||||||
version: 3.1.3
|
version: 3.1.3
|
||||||
js-base64:
|
js-base64:
|
||||||
specifier: ^3.7.6
|
specifier: ^3.7.7
|
||||||
version: 3.7.7
|
version: 3.7.7
|
||||||
jsbarcode:
|
jsbarcode:
|
||||||
specifier: ^3.11.6
|
specifier: ^3.11.6
|
||||||
@@ -7465,6 +7468,10 @@ packages:
|
|||||||
engines: {node: '>= 4'}
|
engines: {node: '>= 4'}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/image-in-browser@3.2.1:
|
||||||
|
resolution: {integrity: sha512-QIhRnkz7ikwtu+U5Q2IkyUeC+7MtiIg0xATF4i72/hxaWjqOPm+VurD7ekCv+dwREmf19nwCurDDeHDayoIgZw==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/image-size@0.5.5:
|
/image-size@0.5.5:
|
||||||
resolution: {integrity: sha512-6TDAlDPZxUFCv+fuOkIoXT/V/f3Qbq8e37p+YOiYrUv3v9cc3/6x78VdfPgFVaB9dZYeLUfKgHRebpkm/oP2VQ==}
|
resolution: {integrity: sha512-6TDAlDPZxUFCv+fuOkIoXT/V/f3Qbq8e37p+YOiYrUv3v9cc3/6x78VdfPgFVaB9dZYeLUfKgHRebpkm/oP2VQ==}
|
||||||
engines: {node: '>=0.10.0'}
|
engines: {node: '>=0.10.0'}
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { Base64 } from 'js-base64';
|
||||||
|
import { Transform, decodeIco, decodeImage, encodeIcoImages, encodePng } from 'image-in-browser';
|
||||||
|
import { useDownloadFileFromBase64 } from '@/composable/downloadBase64';
|
||||||
|
|
||||||
|
const status = ref<'idle' | 'done' | 'error' | 'processing'>('idle');
|
||||||
|
const file = ref<File | null>(null);
|
||||||
|
|
||||||
|
const base64OutputFile = ref('');
|
||||||
|
const fileName = ref('');
|
||||||
|
const fileExtension = ref('');
|
||||||
|
const { download } = useDownloadFileFromBase64(
|
||||||
|
{
|
||||||
|
source: base64OutputFile,
|
||||||
|
filename: fileName,
|
||||||
|
extension: fileExtension,
|
||||||
|
});
|
||||||
|
|
||||||
|
async function onFileUploaded(uploadedFile: File) {
|
||||||
|
file.value = uploadedFile;
|
||||||
|
const fileBuffer = new Uint8Array(await uploadedFile.arrayBuffer());
|
||||||
|
|
||||||
|
fileName.value = `${uploadedFile.name}`;
|
||||||
|
status.value = 'processing';
|
||||||
|
try {
|
||||||
|
if (uploadedFile.type.includes('icon')) {
|
||||||
|
const decodedIco = decodeIco({
|
||||||
|
data: fileBuffer,
|
||||||
|
largest: true,
|
||||||
|
});
|
||||||
|
if (decodedIco == null) {
|
||||||
|
throw new Error('Invalid ICO file!');
|
||||||
|
}
|
||||||
|
const encodedPng = encodePng({
|
||||||
|
image: decodedIco,
|
||||||
|
});
|
||||||
|
fileExtension.value = 'png';
|
||||||
|
base64OutputFile.value = `data:image/png;base64,${Base64.fromUint8Array(encodedPng)}`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const decodedImage = decodeImage({
|
||||||
|
data: fileBuffer,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (decodedImage == null) {
|
||||||
|
throw new Error('Invalid PNG file!');
|
||||||
|
};
|
||||||
|
|
||||||
|
const encodedICO = encodeIcoImages({
|
||||||
|
images: [16, 32, 64, 128, 256].map(size => Transform.copyResize({
|
||||||
|
image: decodedImage,
|
||||||
|
width: size,
|
||||||
|
maintainAspect: true,
|
||||||
|
})),
|
||||||
|
});
|
||||||
|
fileExtension.value = 'ico';
|
||||||
|
base64OutputFile.value = `data:image/x-icon;base64,${Base64.fromUint8Array(encodedICO)}`;
|
||||||
|
}
|
||||||
|
status.value = 'done';
|
||||||
|
|
||||||
|
download();
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
status.value = 'error';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
<div style="flex: 0 0 100%">
|
||||||
|
<div mx-auto max-w-600px>
|
||||||
|
<c-file-upload
|
||||||
|
title="Drag and drop an ICO or PNG/JPEG file here, or click to select a file"
|
||||||
|
accept=".ico,.png,.jpg"
|
||||||
|
paste-image
|
||||||
|
@file-upload="onFileUploaded"
|
||||||
|
/>
|
||||||
|
</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>
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { PictureInPicture } from '@vicons/tabler';
|
||||||
|
import { defineTool } from '../tool';
|
||||||
|
|
||||||
|
export const tool = defineTool({
|
||||||
|
name: 'ICO/PNG converter',
|
||||||
|
path: '/ico-converter',
|
||||||
|
description: 'Convert from PNG/JPEG to/from ICO',
|
||||||
|
keywords: ['ico', 'png', 'jpeg', 'icon', 'converter'],
|
||||||
|
component: () => import('./ico-converter.vue'),
|
||||||
|
icon: PictureInPicture,
|
||||||
|
createdAt: new Date('2024-08-15'),
|
||||||
|
});
|
||||||
@@ -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 dnsQueries } from './dns-queries';
|
import { tool as dnsQueries } from './dns-queries';
|
||||||
|
import { tool as icoConverter } from './ico-converter';
|
||||||
import { tool as emailNormalizer } from './email-normalizer';
|
import { tool as emailNormalizer } from './email-normalizer';
|
||||||
import { tool as bounceParser } from './bounce-parser';
|
import { tool as bounceParser } from './bounce-parser';
|
||||||
import { tool as codeHighlighter } from './code-highlighter';
|
import { tool as codeHighlighter } from './code-highlighter';
|
||||||
@@ -205,6 +206,7 @@ export const toolsByCategory: ToolCategory[] = [
|
|||||||
barcodeReader,
|
barcodeReader,
|
||||||
barcodeGenerator,
|
barcodeGenerator,
|
||||||
heicConverter,
|
heicConverter,
|
||||||
|
icoConverter,
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ const props = withDefaults(defineProps<{
|
|||||||
multiple?: boolean
|
multiple?: boolean
|
||||||
accept?: string
|
accept?: string
|
||||||
title?: string
|
title?: string
|
||||||
|
pasteImage?: boolean
|
||||||
}>(), {
|
}>(), {
|
||||||
multiple: false,
|
multiple: false,
|
||||||
accept: undefined,
|
accept: undefined,
|
||||||
title: 'Drag and drop files here, or click to select files',
|
title: 'Drag and drop files here, or click to select files',
|
||||||
|
pasteImage: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
@@ -16,11 +18,31 @@ const emit = defineEmits<{
|
|||||||
(event: 'fileUpload', file: File): void
|
(event: 'fileUpload', file: File): void
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const { multiple } = toRefs(props);
|
const { multiple, pasteImage } = toRefs(props);
|
||||||
|
|
||||||
const isOverDropZone = ref(false);
|
const isOverDropZone = ref(false);
|
||||||
|
|
||||||
|
function toBase64(file: File) {
|
||||||
|
return new Promise<string>((resolve, reject) => {
|
||||||
|
const reader = new FileReader();
|
||||||
|
reader.readAsDataURL(file);
|
||||||
|
reader.onload = () => resolve(reader.result?.toString() ?? '');
|
||||||
|
reader.onerror = error => reject(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const fileInput = ref<HTMLInputElement | null>(null);
|
const fileInput = ref<HTMLInputElement | null>(null);
|
||||||
|
const imgPreview = ref<HTMLImageElement | null>(null);
|
||||||
|
async function handlePreview(image: File) {
|
||||||
|
if (imgPreview.value) {
|
||||||
|
imgPreview.value.src = await toBase64(image);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function clearPreview() {
|
||||||
|
if (imgPreview.value) {
|
||||||
|
imgPreview.value.src = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function triggerFileInput() {
|
function triggerFileInput() {
|
||||||
fileInput.value?.click();
|
fileInput.value?.click();
|
||||||
@@ -39,7 +61,30 @@ function handleDrop(event: DragEvent) {
|
|||||||
handleUpload(files);
|
handleUpload(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleUpload(files: FileList | null | undefined) {
|
async function onPasteImage(evt: ClipboardEvent) {
|
||||||
|
if (!pasteImage.value) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const items = evt.clipboardData?.items;
|
||||||
|
if (!items) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (let i = 0; i < items.length; i++) {
|
||||||
|
if (items[i].type.includes('image')) {
|
||||||
|
const imageFile = items[i].getAsFile();
|
||||||
|
if (imageFile) {
|
||||||
|
await handlePreview(imageFile);
|
||||||
|
emit('fileUpload', imageFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleUpload(files: FileList | null | undefined) {
|
||||||
|
clearPreview();
|
||||||
|
|
||||||
if (_.isNil(files) || _.isEmpty(files)) {
|
if (_.isNil(files) || _.isEmpty(files)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -49,6 +94,7 @@ function handleUpload(files: FileList | null | undefined) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await handlePreview(files[0]);
|
||||||
emit('fileUpload', files[0]);
|
emit('fileUpload', files[0]);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -60,6 +106,7 @@ function handleUpload(files: FileList | null | undefined) {
|
|||||||
'border-primary border-opacity-100': isOverDropZone,
|
'border-primary border-opacity-100': isOverDropZone,
|
||||||
}"
|
}"
|
||||||
@click="triggerFileInput"
|
@click="triggerFileInput"
|
||||||
|
@paste.prevent="onPasteImage"
|
||||||
@drop.prevent="handleDrop"
|
@drop.prevent="handleDrop"
|
||||||
@dragover.prevent
|
@dragover.prevent
|
||||||
@dragenter="isOverDropZone = true"
|
@dragenter="isOverDropZone = true"
|
||||||
@@ -73,6 +120,7 @@ function handleUpload(files: FileList | null | undefined) {
|
|||||||
:accept="accept"
|
:accept="accept"
|
||||||
@change="handleFileInput"
|
@change="handleFileInput"
|
||||||
>
|
>
|
||||||
|
|
||||||
<slot>
|
<slot>
|
||||||
<span op-70>
|
<span op-70>
|
||||||
{{ title }}
|
{{ title }}
|
||||||
@@ -90,6 +138,22 @@ function handleUpload(files: FileList | null | undefined) {
|
|||||||
<c-button>
|
<c-button>
|
||||||
Browse files
|
Browse files
|
||||||
</c-button>
|
</c-button>
|
||||||
|
|
||||||
|
<div v-if="pasteImage">
|
||||||
|
<!-- separator -->
|
||||||
|
<div my-4 w-full flex items-center justify-center op-70>
|
||||||
|
<div class="h-1px max-w-100px flex-1 bg-gray-300 op-50" />
|
||||||
|
<div class="mx-2 text-gray-400">
|
||||||
|
or
|
||||||
|
</div>
|
||||||
|
<div class="h-1px max-w-100px flex-1 bg-gray-300 op-50" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<p>Paste an image from clipboard</p>
|
||||||
|
</div>
|
||||||
</slot>
|
</slot>
|
||||||
|
<div mt-2>
|
||||||
|
<img ref="imgPreview" width="150">
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
Reference in new issue
Block a user