mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
compress image added to ações
This commit is contained in:
@@ -65,7 +65,7 @@ import { MediaCapture } from '@ionic-native/media-capture/ngx';
|
||||
import { Media } from '@ionic-native/media/ngx';
|
||||
import { StreamingMedia } from '@ionic-native/streaming-media/ngx';
|
||||
import { PhotoViewer } from '@ionic-native/photo-viewer/ngx';
|
||||
|
||||
import {NgxImageCompressService} from 'ngx-image-compress';
|
||||
|
||||
/* import { FCM } from '@ionic-native/fcm/ngx';
|
||||
import { FirebaseX } from '@ionic-native/firebase-x/ngx'; */
|
||||
@@ -132,7 +132,8 @@ import { FirebaseX } from '@ionic-native/firebase-x/ngx'; */
|
||||
MediaCapture,
|
||||
Media,
|
||||
StreamingMedia,
|
||||
PhotoViewer
|
||||
PhotoViewer,
|
||||
NgxImageCompressService
|
||||
],
|
||||
bootstrap: [AppComponent],
|
||||
schemas: [CUSTOM_ELEMENTS_SCHEMA]
|
||||
|
||||
@@ -19,6 +19,7 @@ import { ThemeService } from 'src/app/services/theme.service';
|
||||
import { Camera, CameraResultType, CameraSource, Photo } from '@capacitor/camera';
|
||||
|
||||
import { Filesystem, Directory } from '@capacitor/filesystem';
|
||||
import { NgxImageCompressService } from "ngx-image-compress";
|
||||
|
||||
const IMAGE_DIR = 'stored-images';
|
||||
|
||||
@@ -72,6 +73,9 @@ export class NewPublicationPage implements OnInit {
|
||||
capturedImageTitle: any;
|
||||
public photos: any[] = [];
|
||||
|
||||
imgResultBeforeCompress: string;
|
||||
imgResultAfterCompress: string;
|
||||
|
||||
constructor(
|
||||
private modalController: ModalController,
|
||||
public photoService: PhotoService,
|
||||
@@ -83,6 +87,7 @@ export class NewPublicationPage implements OnInit {
|
||||
public ThemeService: ThemeService,
|
||||
private platform: Platform,
|
||||
private loadingCtrl: LoadingController,
|
||||
public imageCompress: NgxImageCompressService
|
||||
) {
|
||||
|
||||
this.publicationType = this.navParams.get('publicationType');
|
||||
@@ -104,13 +109,11 @@ export class NewPublicationPage implements OnInit {
|
||||
|
||||
async takePicture() {
|
||||
const image = await Camera.getPhoto({
|
||||
quality: 50,
|
||||
height: 400,
|
||||
width:400,
|
||||
quality: 20,
|
||||
allowEditing: false,
|
||||
resultType: CameraResultType.Uri,
|
||||
source: CameraSource.Camera // Camera, Photos or Prompt!
|
||||
|
||||
|
||||
});
|
||||
|
||||
if (image) {
|
||||
@@ -120,13 +123,13 @@ export class NewPublicationPage implements OnInit {
|
||||
}
|
||||
|
||||
|
||||
imageSize(image){
|
||||
var canvas = document.createElement('canvas');
|
||||
var ctx = canvas.getContext('2d');
|
||||
canvas.width=100
|
||||
canvas.height=34
|
||||
ctx.drawImage(image, 0, 0, 100, 34);
|
||||
document.body.appendChild(canvas);
|
||||
imageSize(image) {
|
||||
var canvas = document.createElement('canvas');
|
||||
var ctx = canvas.getContext('2d');
|
||||
canvas.width = 100
|
||||
canvas.height = 34
|
||||
ctx.drawImage(image, 0, 0, 100, 34);
|
||||
document.body.appendChild(canvas);
|
||||
}
|
||||
|
||||
convertBlobToBase64 = (blob: Blob) => new Promise((resolve, reject) => {
|
||||
@@ -394,9 +397,7 @@ export class NewPublicationPage implements OnInit {
|
||||
|
||||
async selectImage() {
|
||||
const image = await Camera.getPhoto({
|
||||
quality: 50,
|
||||
height: 400,
|
||||
width: 400,
|
||||
quality: 20,
|
||||
allowEditing: false,
|
||||
resultType: CameraResultType.Uri,
|
||||
source: CameraSource.Camera // Camera, Photos or Prompt!
|
||||
@@ -407,7 +408,7 @@ export class NewPublicationPage implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Create a new file from a capture image
|
||||
async saveImage(photo: Photo) {
|
||||
@@ -496,12 +497,43 @@ export class NewPublicationPage implements OnInit {
|
||||
|
||||
this.capturedImage = this.images[0].data
|
||||
|
||||
this.compressFile();
|
||||
|
||||
loading.dismiss();
|
||||
|
||||
}
|
||||
|
||||
/* compressImage() {
|
||||
let image = this.capturedImage;
|
||||
this.imageCompress.compressFile(image, orientation, 50, 50,).then(() => {
|
||||
|
||||
this.imgResultBeforeCompress = image;
|
||||
console.log('Size in bytes was:', this.imageCompress.byteCount(image));
|
||||
|
||||
this.imageCompress.compressFile(image, orientation, 50, 50).then(
|
||||
result => {
|
||||
this.imgResultAfterCompress = result;
|
||||
console.log('Size in bytes is now:', this.imageCompress.byteCount(result));
|
||||
}
|
||||
);
|
||||
})
|
||||
} */
|
||||
|
||||
compressFile() {
|
||||
|
||||
//this.imgResultBeforeCompress = image;
|
||||
this.imageCompress.getOrientation(this.capturedImage).then((orientation) => {
|
||||
console.log('Size in bytes was:', this.imageCompress.byteCount(this.capturedImage));
|
||||
this.imageCompress.compressFile(this.capturedImage, orientation, 20, 20).then(
|
||||
result => {
|
||||
this.capturedImage = result;
|
||||
console.log('Size in bytes is now:', this.imageCompress.byteCount(result));
|
||||
}
|
||||
);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user