Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion #225 implemented #226

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 27 additions & 8 deletions src/lib/component/util/server-icon-converter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
import {toast} from "@zerodevx/svelte-toast";
import {incrementTracker} from "$lib/tracker/tracker";

let resizedImage = '/display/packpng.svg'
let fileInput

function onFileSelected(e) {
let imageFile = e.target.files[0];
let imageFile = e.target.files[0]
processImageFile(imageFile)
}

function processImageFile(imageFile) {
let reader = new FileReader();
reader.onload = e => {
reader.onload = (e) => {
let image = new Image();
image.src = e.target.result;

Expand All @@ -16,14 +23,28 @@
canvas.height = 64;
ctx.drawImage(image, 0, 0, 64, 64);
resizedImage = canvas.toDataURL('image/png'); // Use 'image/png' to preserve transparency

// Set the src attribute of the <img> element to the resized image data URL
document.getElementById('resizedImage').src = resizedImage;
};
};
reader.readAsDataURL(imageFile);
}

document.addEventListener('paste', function (event) {
const items = event.clipboardData.items
// Check to see if there is only 1 image in the clipboard
if (items.length === 1 && items[0].type.indexOf('image') !== -1) {
const imageFile = items[0].getAsFile()
processImageFile(imageFile)
} else {
toast.push('Please paste an image.', {
theme: {
'--toastColor': 'mintcream',
'--toastBackground': '#F56565',
'--toastBarBackground': '#C53030',
},
})
}
})

function downloadToast() {
toast.push('Downloaded successfully!', {
theme: {
Expand All @@ -35,14 +56,12 @@

incrementTracker("server-icons-served")
}

let fileInput, resizedImage
</script>

<main class="w-[90%] lg:w-[60%] mt-5 flex-col flex justify-center items-center">

<h3 class="font-medium text-white text-20px text-left mb-2.5">
Upload an image
Upload or paste an image
</h3>
<input type="file" accept=".jpg, .jpeg, .png" class="button w-[300px] md:w-[500px]" on:change={(e)=>onFileSelected(e)}
bind:this={fileInput}>
Expand Down