how to resize base64 image in angular
Add this helper function outside of the given component:
function compressImage(src, newX, newY) {
return new Promise((res, rej) => {
const img = new Image();
img.src = src;
img.onload = () => {
const elem = document.createElement('canvas');
elem.width = newX;
elem.height = newY;
const ctx = elem.getContext('2d');
ctx.drawImage(img, 0, 0, newX, newY);
const data = ctx.canvas.toDataURL();
res(data);
}
img.onerror = error => rej(error);
})
}
Then call like so:
compressImage(base64, 100, 100).then(compressed => {
this.resizedBase64 = compressed;
})
How to resize a base64 image to occupy less?
To make it smaller you have to get rid of information. Do something like JPEG, it will focus on removing information that is less relevant, many times a JPEG image looks just fine but is like 10 times smaller.
How to resize file and then convert to base64?
The ImagePicker library has two properties for resizing the image maxHeight
and maxWidth
Here's an example:
var image = await ImagePicker.pickImage(
source: ImageSource.camera,
maxHeight: 150.0,
maxWidth: 150.0,
);
Related Topics
Install PHP Intl Extension on Macos
Php 7 With Phpmyadmin Gives Lots of Deprecation Notices
Laravel Eloquent Sum of Multiplied Columns
How to Convert a 13 Digit Unix Timestamp to Date and Time
Laravel-5 How to Populate Select Box from Database With Id Value and Name Value
Failed to Open the System Default Web Browser. Is One Installed - Pgadmin4
How to Pass a Number With Forward Slash "/" to Codeigniter Controller Using Ajax
Laravel: Pdoexception: Could Not Find Driver
Laravel Ajax Response Return HTML Elements
How to Add Class to Link in Wp_Nav_Menu
Windows 10 Docker:/Usr/Bin/Env: 'Php\R': No Such File or Directory
Php Get Number of Week for Month
Why Does This Pdo Statement Silently Fail
How to Implement Basic "Long Polling"
Call to a Member Function on a Non-Object
Show a Number to Two Decimal Places
Are Pdo Prepared Statements Sufficient to Prevent SQL Injection