mirror of
https://github.com/MrUnknownDE/VRCX.git
synced 2026-05-06 14:46:04 +02:00
Only compress PNG when needed, instance-queue-left
This commit is contained in:
+28
-18
@@ -68,36 +68,39 @@ namespace VRCX
|
|||||||
public byte[] ResizeImageToFitLimits(byte[] imageData, int maxWidth = 2000, int maxHeight = 2000, long maxSize = 10_000_000)
|
public byte[] ResizeImageToFitLimits(byte[] imageData, int maxWidth = 2000, int maxHeight = 2000, long maxSize = 10_000_000)
|
||||||
{
|
{
|
||||||
using var fileMemoryStream = new MemoryStream(imageData);
|
using var fileMemoryStream = new MemoryStream(imageData);
|
||||||
System.Drawing.Bitmap image = new System.Drawing.Bitmap(fileMemoryStream);
|
var image = new Bitmap(fileMemoryStream);
|
||||||
|
|
||||||
|
// for APNG, check if image is png format and less than maxSize
|
||||||
|
if (image.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Png) &&
|
||||||
|
imageData.Length < maxSize &&
|
||||||
|
image.Width <= maxWidth &&
|
||||||
|
image.Height <= maxHeight)
|
||||||
|
{
|
||||||
|
return imageData;
|
||||||
|
}
|
||||||
|
|
||||||
if (image.Width > maxWidth)
|
if (image.Width > maxWidth)
|
||||||
{
|
{
|
||||||
var sizingFactor = image.Width / (double)maxWidth;
|
var sizingFactor = image.Width / (double)maxWidth;
|
||||||
int newHeight = (int)Math.Round(image.Height / sizingFactor);
|
var newHeight = (int)Math.Round(image.Height / sizingFactor);
|
||||||
image = new System.Drawing.Bitmap(image, maxWidth, newHeight);
|
image = new Bitmap(image, maxWidth, newHeight);
|
||||||
}
|
}
|
||||||
if (image.Height > maxHeight)
|
if (image.Height > maxHeight)
|
||||||
{
|
{
|
||||||
var sizingFactor = image.Height / (double)maxHeight;
|
var sizingFactor = image.Height / (double)maxHeight;
|
||||||
int newWidth = (int)Math.Round(image.Width / sizingFactor);
|
var newWidth = (int)Math.Round(image.Width / sizingFactor);
|
||||||
image = new System.Drawing.Bitmap(image, newWidth, maxHeight);
|
image = new Bitmap(image, newWidth, maxHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveToFileToUpload()
|
SaveToFileToUpload();
|
||||||
{
|
|
||||||
using var imageSaveMemoryStream = new MemoryStream();
|
|
||||||
image.Save(imageSaveMemoryStream, System.Drawing.Imaging.ImageFormat.Png);
|
|
||||||
imageData = imageSaveMemoryStream.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
saveToFileToUpload();
|
|
||||||
|
|
||||||
for (int i = 0; i < 250 && imageData.Length > maxSize; i++)
|
for (int i = 0; i < 250 && imageData.Length > maxSize; i++)
|
||||||
{
|
{
|
||||||
saveToFileToUpload();
|
SaveToFileToUpload();
|
||||||
if (imageData.Length < maxSize)
|
if (imageData.Length < maxSize)
|
||||||
break;
|
break;
|
||||||
int newWidth = image.Width;
|
|
||||||
int newHeight = image.Height;
|
int newWidth;
|
||||||
|
int newHeight;
|
||||||
if (image.Width > image.Height)
|
if (image.Width > image.Height)
|
||||||
{
|
{
|
||||||
newWidth = image.Width - 25;
|
newWidth = image.Width - 25;
|
||||||
@@ -108,7 +111,7 @@ namespace VRCX
|
|||||||
newHeight = image.Height - 25;
|
newHeight = image.Height - 25;
|
||||||
newWidth = (int)Math.Round(image.Width / (image.Height / (double)newHeight));
|
newWidth = (int)Math.Round(image.Width / (image.Height / (double)newHeight));
|
||||||
}
|
}
|
||||||
image = new System.Drawing.Bitmap(image, newWidth, newHeight);
|
image = new Bitmap(image, newWidth, newHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imageData.Length > maxSize)
|
if (imageData.Length > maxSize)
|
||||||
@@ -117,6 +120,13 @@ namespace VRCX
|
|||||||
}
|
}
|
||||||
|
|
||||||
return imageData;
|
return imageData;
|
||||||
|
|
||||||
|
void SaveToFileToUpload()
|
||||||
|
{
|
||||||
|
using var imageSaveMemoryStream = new MemoryStream();
|
||||||
|
image.Save(imageSaveMemoryStream, System.Drawing.Imaging.ImageFormat.Png);
|
||||||
|
imageData = imageSaveMemoryStream.ToArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
+12
-10
@@ -5227,6 +5227,11 @@ speechSynthesis.getVoices();
|
|||||||
$app.instanceQueueReady(instanceId);
|
$app.instanceQueueReady(instanceId);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'instance-queue-left':
|
||||||
|
console.log('instance-queue-left', content);
|
||||||
|
$app.instanceQueueClear();
|
||||||
|
break;
|
||||||
|
|
||||||
case 'content-refresh':
|
case 'content-refresh':
|
||||||
var contentType = content.contentType;
|
var contentType = content.contentType;
|
||||||
console.log('content-refresh', content);
|
console.log('content-refresh', content);
|
||||||
@@ -29003,16 +29008,13 @@ speechSynthesis.getVoices();
|
|||||||
// workerTimers.setTimeout(this.instanceQueueTimeout, 3600000);
|
// workerTimers.setTimeout(this.instanceQueueTimeout, 3600000);
|
||||||
};
|
};
|
||||||
|
|
||||||
// $app.methods.instanceQueueTimeout = function () {
|
$app.methods.instanceQueueClear = function () {
|
||||||
// // remove instance from queue after 1hour of inactivity
|
// remove all instances from queue
|
||||||
// API.queuedInstances.forEach((ref) => {
|
API.queuedInstances.forEach((ref) => {
|
||||||
// // 59mins
|
ref.$msgBox.close();
|
||||||
// if (Date.now() - ref.updatedAt > 3540000) {
|
API.queuedInstances.delete(ref.location);
|
||||||
// ref.$msgBox.close();
|
});
|
||||||
// API.queuedInstances.delete(ref.location);
|
};
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// };
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {{ groupId: string }} params
|
* @param {{ groupId: string }} params
|
||||||
|
|||||||
Reference in New Issue
Block a user