mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Merge branch 'feat/potrace' into chore/all-my-stuffs
# Conflicts: # components.d.ts # package.json # pnpm-lock.yaml # src/tools/index.ts # vite.config.ts
This commit is contained in:
commit
a63775f189
5 files changed
+1160
-1
No files matched your search
@@ -81,6 +81,7 @@
|
||||
"@types/emscripten": "^1.39.10",
|
||||
"@types/figlet": "^1.5.8",
|
||||
"@types/markdown-it": "^13.0.7",
|
||||
"@types/potrace": "^2.1.5",
|
||||
"@vicons/material": "^0.12.0",
|
||||
"@vicons/tabler": "^0.12.0",
|
||||
"@vueuse/core": "^10.11.1",
|
||||
@@ -186,6 +187,7 @@
|
||||
"shiki": "^1.22.0",
|
||||
"postal-mime": "^2.2.7",
|
||||
"qpdf-wasm-esm-embedded": "^1.1.1",
|
||||
"potrace": "^2.1.8",
|
||||
"qrcode": "^1.5.1",
|
||||
"rtf-stream-parser": "^3.8.0",
|
||||
"sql-formatter": "^13.0.0",
|
||||
|
||||
Generated
+1040
-1
File diff suppressed because it is too large.
Load diff
@@ -70,6 +70,7 @@ import { tool as jsonToGo } from './json-to-go';
|
||||
import { tool as jsonToSchema } from './json-to-schema';
|
||||
import { tool as markdownToHtml } from './markdown-to-html';
|
||||
import { tool as nginxFormatter } from './nginx-formatter';
|
||||
import { tool as potrace } from './potrace';
|
||||
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
|
||||
import { tool as numeronymGenerator } from './numeronym-generator';
|
||||
import { tool as macAddressGenerator } from './mac-address-generator';
|
||||
@@ -264,6 +265,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
icoConverter,
|
||||
imageConverter,
|
||||
ocrImage,
|
||||
potrace,
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { ArrowsShuffle } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Image to SVG (potrace)',
|
||||
path: '/potrace',
|
||||
description: 'Convert an raster image to vectorial SVG',
|
||||
keywords: ['potrace', 'image', 'svg', 'raster', 'vectorial'],
|
||||
component: () => import('./potrace.vue'),
|
||||
icon: ArrowsShuffle,
|
||||
createdAt: new Date('2024-05-11'),
|
||||
});
|
||||
@@ -0,0 +1,104 @@
|
||||
<script setup lang="ts">
|
||||
import { Buffer } from 'node:buffer';
|
||||
import type { Ref } from 'vue';
|
||||
import potrace from 'potrace';
|
||||
import { Base64 } from 'js-base64';
|
||||
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
||||
|
||||
async function traceAsync(input: Buffer) {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
potrace.trace(input, (err: Error | null, svg: string) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
resolve(svg);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function posterizeAsync(input: Buffer) {
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
potrace.posterize(input,
|
||||
(err: Error | null, svg: string) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
}
|
||||
resolve(svg);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function file2Buffer(file: File) {
|
||||
return new Promise<Buffer>((resolve, _reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.addEventListener('load', () => {
|
||||
const buffer = Buffer.from(reader.result as ArrayBuffer);
|
||||
resolve(buffer);
|
||||
});
|
||||
reader.readAsArrayBuffer(file);
|
||||
});
|
||||
}
|
||||
|
||||
const posterize = ref(true);
|
||||
const fileInput = ref() as Ref<File>;
|
||||
const svg = computedAsync(async () => {
|
||||
const trace = !posterize.value;
|
||||
const file = fileInput.value;
|
||||
if (!file) {
|
||||
return '';
|
||||
}
|
||||
try {
|
||||
const buffer = await file2Buffer(file);
|
||||
return (trace ? await traceAsync(buffer) : await posterizeAsync(buffer));
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
|
||||
const svgBase64 = computed(() => svg.value ? `data:image/svg+xml;base64,${Base64.encode(svg.value)}` : '');
|
||||
|
||||
async function onUpload(file: File) {
|
||||
if (file) {
|
||||
fileInput.value = file;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div style="max-width: 600px;">
|
||||
<c-file-upload
|
||||
title="Drag and drop an image here, or click to select a file"
|
||||
:paste-image="true"
|
||||
@file-upload="onUpload"
|
||||
/>
|
||||
|
||||
<div style="text-align: center;">
|
||||
<n-checkbox v-model:checked="posterize" mt-2>
|
||||
Posterize?
|
||||
</n-checkbox>
|
||||
</div>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<div>
|
||||
<h3>Potrace result</h3>
|
||||
<TextareaCopyable
|
||||
:value="svg"
|
||||
word-wrap
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<div style="text-align: center;">
|
||||
<img width="150" :src="svgBase64" style="background-color: white">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
::v-deep(.n-upload-trigger) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user