Skip to content

Commit

Permalink
Fix print upload size
Browse files Browse the repository at this point in the history
  • Loading branch information
Natsumi-sama committed Dec 11, 2024
1 parent 766cc98 commit 6ab68ce
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 8 deletions.
55 changes: 50 additions & 5 deletions Dotnet/AppApi/AppApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,9 @@ public byte[] ResizeImageToFitLimits(byte[] imageData, bool matchingDimensions,
{
var newSize = Math.Max(image.Width, image.Height);
var newImage = new Bitmap(newSize, newSize);
using (var graphics = Graphics.FromImage(newImage))
{
graphics.Clear(Color.Transparent);
graphics.DrawImage(image, new Rectangle((newSize - image.Width) / 2, (newSize - image.Height) / 2, image.Width, image.Height));
}
using var graphics = Graphics.FromImage(newImage);
graphics.Clear(Color.Transparent);
graphics.DrawImage(image, new Rectangle((newSize - image.Width) / 2, (newSize - image.Height) / 2, image.Width, image.Height));
image.Dispose();
image = newImage;
}
Expand Down Expand Up @@ -140,6 +138,53 @@ void SaveToFileToUpload()
imageData = imageSaveMemoryStream.ToArray();
}
}

public byte[] ResizePrintImage(byte[] imageData)
{
var inputImage = ResizeImageToFitLimits(imageData, false, 1920, 1080);
using var fileMemoryStream = new MemoryStream(inputImage);
var image = new Bitmap(fileMemoryStream);

// increase size to 1920x1080
if (image.Width < 1920 || image.Height < 1080)
{
var newHeight = image.Height;
var newWidth = image.Width;
if (image.Width < 1920)
{
newWidth = 1920;
newHeight = (int)Math.Round(image.Height / (image.Width / (double)newWidth));
}
if (image.Height < 1080)
{
newHeight = 1080;
newWidth = (int)Math.Round(image.Width / (image.Height / (double)newHeight));
}
var resizedImage = new Bitmap(1920, 1080);
using var graphics1 = Graphics.FromImage(resizedImage);
graphics1.Clear(Color.White);
var x = (1920 - newWidth) / 2;
var y = (1080 - newHeight) / 2;
graphics1.DrawImage(image, new Rectangle(x, y, newWidth, newHeight));
image.Dispose();
image = resizedImage;
}

// add white border
// wtf are these magic numbers
const int xOffset = 64; // 2048 / 32
const int yOffset = 69; // 1440 / 20.869
var newImage = new Bitmap(2048, 1440);
using var graphics = Graphics.FromImage(newImage);
graphics.Clear(Color.White);
graphics.DrawImage(image, new Rectangle(xOffset, yOffset, image.Width, image.Height));
image.Dispose();
image = newImage;

using var imageSaveMemoryStream = new MemoryStream();
image.Save(imageSaveMemoryStream, System.Drawing.Imaging.ImageFormat.Png);
return imageSaveMemoryStream.ToArray();
}

/// <summary>
/// Computes the signature of the file represented by the specified base64-encoded string using the librsync library.
Expand Down
2 changes: 1 addition & 1 deletion Dotnet/WebApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private static async Task PrintImageUpload(HttpWebRequest request, IDictionary<s
request.ContentType = "multipart/form-data; boundary=" + boundary;
var requestStream = request.GetRequestStream();
var imageData = options["imageData"] as string;
var fileToUpload = AppApi.Instance.ResizeImageToFitLimits(Convert.FromBase64String(imageData), false, 1920, 1080);
var fileToUpload = AppApi.Instance.ResizePrintImage(Convert.FromBase64String(imageData));
const string fileFormKey = "image";
const string fileName = "image";
const string fileMimeType = "image/png";
Expand Down
6 changes: 4 additions & 2 deletions html/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -691,11 +691,13 @@ speechSynthesis.getVoices();
if (
ref.$isVRCPlus &&
ref.badges &&
ref.badges.every((x) => x.badgeName !== 'Supporter')
ref.badges.every(
(x) => x.badgeId !== 'bdg_754f9935-0f97-49d8-b857-95afb9b673fa'
)
) {
// I doubt this will last long
ref.badges.unshift({
badgeId: 'bdg_system_supporter',
badgeId: 'bdg_754f9935-0f97-49d8-b857-95afb9b673fa',
badgeName: 'Supporter',
badgeDescription: 'Supports VRChat through VRC+',
badgeImageUrl:
Expand Down

0 comments on commit 6ab68ce

Please sign in to comment.