mirror of
https://codeberg.org/beerbrawl/beerbrawl.git
synced 2024-09-23 05:40:51 +02:00
feat(#33): correct html type - backend calls(comments)
This commit is contained in:
parent
7a34973f58
commit
c0baf732d4
|
@ -1,4 +1,4 @@
|
|||
import { Component, input } from '@angular/core';
|
||||
import { Component, inject, input } from '@angular/core';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
import { MatCardModule } from '@angular/material/card';
|
||||
import { MatIcon } from '@angular/material/icon';
|
||||
|
@ -17,6 +17,8 @@ export class ImageUploadComponent {
|
|||
tournamentId = input<number>();
|
||||
token = input<string>();
|
||||
|
||||
//sharedMediaService = inject(SharedMediaService);
|
||||
|
||||
async onFileSelected(event: Event): Promise<void> {
|
||||
this.errorMessage = '';
|
||||
const file = (event.target as HTMLInputElement).files?.[0];
|
||||
|
@ -25,8 +27,10 @@ export class ImageUploadComponent {
|
|||
reader.onload = async (e: ProgressEvent<FileReader>) => {
|
||||
const img = new Image();
|
||||
img.onload = async () => {
|
||||
const formattedBlob = await this.formatImageTo4by3(img);
|
||||
this.selectedImage = await this.blobToDataURL(formattedBlob);
|
||||
const formattedImage = await this.formatImageTo4by3(img);
|
||||
this.selectedImage = await this.blobToDataURL(formattedImage);
|
||||
const formDataImage = new FormData().append('image', formattedImage, `t-${this.tournamentId}_${Date.now().toLocaleString()}_submission.jpg`);
|
||||
//this.sharedMediaService.create(dto, formDataImage);
|
||||
};
|
||||
if (e.target && e.target.result) {
|
||||
img.src = e.target.result as string;
|
||||
|
@ -48,7 +52,6 @@ export class ImageUploadComponent {
|
|||
let newWidth = image.width;
|
||||
let newHeight = image.height;
|
||||
|
||||
// Adjust the dimensions to maintain a 4:3 aspect ratio
|
||||
if (newWidth / newHeight > aspectRatio) {
|
||||
newWidth = newHeight * aspectRatio;
|
||||
} else {
|
||||
|
@ -58,10 +61,8 @@ export class ImageUploadComponent {
|
|||
canvas.width = newWidth;
|
||||
canvas.height = newHeight;
|
||||
|
||||
// Draw the image on the canvas
|
||||
ctx.drawImage(image, 0, 0, newWidth, newHeight);
|
||||
|
||||
// Create a Blob from the canvas
|
||||
canvas.toBlob(blob => {
|
||||
if (blob) {
|
||||
resolve(blob);
|
||||
|
|
Loading…
Reference in a new issue