Automatically resize images to fit limits (#831)

Resize images for Avatars, Worlds, Gallery, Icons and Emojis when uploading if it exceeds VRChats limits (2000 pixels in any dimension and 10MB file size).
This commit is contained in:
Nekromateion
2024-06-26 13:29:46 +02:00
committed by GitHub
parent 3ab1cf1d48
commit 873c1d38f0
4 changed files with 91 additions and 24 deletions

View File

@@ -21598,8 +21598,8 @@ speechSynthesis.getVoices();
if (!files.length) {
return;
}
if (files[0].size >= 10000000) {
// 10MB
if (files[0].size >= 100000000) {
// 100MB
$app.$message({
message: 'File size too large',
type: 'error'
@@ -21665,8 +21665,8 @@ speechSynthesis.getVoices();
if (!files.length) {
return;
}
if (files[0].size >= 10000000) {
// 10MB
if (files[0].size >= 100000000) {
// 100MB
$app.$message({
message: 'File size too large',
type: 'error'
@@ -21674,7 +21674,7 @@ speechSynthesis.getVoices();
this.clearInviteImageUpload();
return;
}
if (!files[0].type.match(/image.png/)) {
if (!files[0].type.match(/image.*/)) {
$app.$message({
message: "File isn't a png",
type: 'error'
@@ -22679,6 +22679,11 @@ speechSynthesis.getVoices();
return response;
};
$app.methods.resizeImageToFitLimits = async function (file) {
var response = await AppApi.ResizeImageToFitLimits(file);
return response;
};
$app.methods.genSig = async function (file) {
var response = await AppApi.SignFile(file);
return response;
@@ -22706,8 +22711,8 @@ speechSynthesis.getVoices();
clearFile();
return;
}
if (files[0].size >= 10000000) {
// 10MB
if (files[0].size >= 100000000) {
// 100MB
$app.$message({
message: 'File size too large',
type: 'error'
@@ -22715,7 +22720,7 @@ speechSynthesis.getVoices();
clearFile();
return;
}
if (!files[0].type.match(/image.png/)) {
if (!files[0].type.match(/image.*/)) {
$app.$message({
message: "File isn't a png",
type: 'error'
@@ -22727,7 +22732,8 @@ speechSynthesis.getVoices();
this.changeAvatarImageDialogLoading = true;
var r = new FileReader();
r.onload = async function (file) {
var base64File = btoa(r.result);
var base64File = await $app.resizeImageToFitLimits(btoa(r.result));
// 10MB
var fileMd5 = await $app.genMd5(base64File);
var fileSizeInBytes = parseInt(file.total, 10);
var base64SignatureFile = await $app.genSig(base64File);
@@ -23041,8 +23047,8 @@ speechSynthesis.getVoices();
clearFile();
return;
}
if (files[0].size >= 10000000) {
// 10MB
if (files[0].size >= 100000000) {
// 100MB
$app.$message({
message: 'File size too large',
type: 'error'
@@ -23050,7 +23056,7 @@ speechSynthesis.getVoices();
clearFile();
return;
}
if (!files[0].type.match(/image.png/)) {
if (!files[0].type.match(/image.*/)) {
$app.$message({
message: "File isn't a png",
type: 'error'
@@ -23062,7 +23068,8 @@ speechSynthesis.getVoices();
this.changeWorldImageDialogLoading = true;
var r = new FileReader();
r.onload = async function (file) {
var base64File = btoa(r.result);
var base64File = await $app.resizeImageToFitLimits(btoa(r.result));
// 10MB
var fileMd5 = await $app.genMd5(base64File);
var fileSizeInBytes = parseInt(file.total, 10);
var base64SignatureFile = await $app.genSig(base64File);
@@ -25073,8 +25080,8 @@ speechSynthesis.getVoices();
if (!files.length) {
return;
}
if (files[0].size >= 10000000) {
// 10MB
if (files[0].size >= 100000000) {
// 100MB
$app.$message({
message: 'File size too large',
type: 'error'
@@ -25184,8 +25191,8 @@ speechSynthesis.getVoices();
if (!files.length) {
return;
}
if (files[0].size >= 10000000) {
// 10MB
if (files[0].size >= 100000000) {
// 100MB
$app.$message({
message: 'File size too large',
type: 'error'