This commit is contained in:
Peter Maquiran
2023-02-10 13:07:08 +01:00
parent d933df5b31
commit 16d2fac864
2 changed files with 18 additions and 62 deletions
@@ -18,8 +18,6 @@ import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera
import { Filesystem, Directory } from '@capacitor/filesystem';
import { NgxImageCompressService } from "ngx-image-compress";
import { readAndCompressImage } from 'browser-image-resizer';
import { environment } from 'src/environments/environment';
const IMAGE_DIR = 'stored-images';
@@ -110,7 +108,7 @@ export class NewPublicationPage implements OnInit {
}
async takePicture() {
alert('take')
const capturedImage = await Camera.getPhoto({
quality: 90,
// allowEditing: true,
@@ -121,30 +119,11 @@ export class NewPublicationPage implements OnInit {
const response = await fetch(capturedImage.webPath!);
const blob = await response.blob();
const config = {
quality: 0.5,
maxWidth: 800,
debug: true
};
var file = new File([blob], "camera.jpg");
// Note: A single file comes from event.target.files on <input>
readAndCompressImage(file, config)
.then(resizedImage => {
console.log('resizedImage', resizedImage);
this.convertBlobToBase64Worker.postMessage(resizedImage);
this.convertBlobToBase64Worker.onmessage = async (oEvent)=> {
this.capturedImage = oEvent.data
}
})
.then(result => {
// TODO: Handle the result
console.log('result', result);
});
this.convertBlobToBase64Worker.postMessage(blob);
this.convertBlobToBase64Worker.onmessage = async (oEvent)=> {
this.capturedImage = oEvent.data
}
}
imageSize(image) {
@@ -200,35 +179,12 @@ export class NewPublicationPage implements OnInit {
const response = await fetch(capturedImage.webPath!);
const blob = await response.blob();
const config = {
quality: 0.9,
maxWidth: 800,
debug: !environment.production
};
var file = new File([blob], "camera.jpg");
// Note: A single file comes from event.target.files on <input>
readAndCompressImage(file, config)
.then(resizedImage => {
console.log('resizedImage', resizedImage);
this.convertBlobToBase64Worker.postMessage(resizedImage);
this.convertBlobToBase64Worker.onmessage = async (oEvent)=> {
this.capturedImage = oEvent.data
}
})
.then(result => {
// TODO: Handle the result
// console.log('result', result);
});
this.convertBlobToBase64Worker.postMessage(blob);
this.convertBlobToBase64Worker.onmessage = async (oEvent)=> {
this.capturedImage = oEvent.data
}
}
@@ -242,7 +198,7 @@ export class NewPublicationPage implements OnInit {
this.Form = new FormGroup({
Subject: new FormControl(this.pub.Title, [
Validators.required,
//Validators.required,
// Validators.minLength(4)
]),
capturedImage: new FormControl(this.capturedImage, [
@@ -285,11 +241,11 @@ export class NewPublicationPage implements OnInit {
try {
await this.publications.UpdatePublication(this.publication.ProcessId, this.publication).toPromise()
this.toastService.successMessage("Publicação editada")
this.toastService._successMessage("Publicação editada")
this.close();
} catch (error) {
this.toastService.badRequest("Publicação não editada")
this.toastService._badRequest("Publicação não editada")
} finally {
loader.remove()
}