When using images from google images seems to be a lot of images that are base64 encodeded.
Heres a little patch to fix those so they work.
Add this new function.
private static byte[] LoadImage(string data)
{
//data:image/gif;base64,
//data:image/jpeg;base64,
//data:image/png;base64,
data = data.Replace("data:image/gif;base64,", "");
data = data.Replace("data:image/jpeg;base64,", "");
data = data.Replace("data:image/png;base64,", "");
return Convert.FromBase64String(data);
}Now go to the function
private IEnumerator DownloadImage(DownloadRequest request)And change it to be like this.
Basically just moves the defining of imagebytes to the top, And putting a if conidtion for it ifsees the data:image tag then it fills the images bytes with the base64 decoded info.
Other wise it goes back to doing the normal stuff.
private IEnumerator DownloadImage(DownloadRequest request)
{
byte[] imageBytes;
if (request.Url.StartsWith("data:image"))
{
imageBytes = LoadImage(request.Url);
if (imageBytes.Length > signArtist.Settings.MaxFileSizeInBytes )
{
//The file is too large, show a message to the player and attempt to start the next download.
signArtist.SendMessage(request.Sender, "FileTooLarge", imageBytes.Length, signArtist.Settings.MaxFileSizeInBytes);
StartNextDownload(true);
yield break;
}
}
else
{
if (ItemManager.itemDictionaryByName.ContainsKey(request.Url))
{
request.Url = string.Format(ItemIconUrl, request.Url);
}
UnityWebRequest www = UnityWebRequest.Get(request.Url);
yield return http://www.SendWebRequest();
// Verify that there is a valid reference to the plugin from this class.
if (signArtist == null)
{
throw new NullReferenceException("signArtist");
}
// Verify that the webrequest was succesful.
if (www.isNetworkError || http://www.isHttpError)
{
// The webrequest wasn't succesful, show a message to the player and attempt to start the next download.
signArtist.SendMessage(request.Sender, "WebErrorOccurred", http://www.error);
http://www.Dispose();
StartNextDownload(true);
yield break;
}
//Verify that the file doesn't exceed the maximum configured filesize.
if (www.downloadedBytes > signArtist.Settings.MaxFileSizeInBytes )
{
//The file is too large, show a message to the player and attempt to start the next download.
signArtist.SendMessage(request.Sender, "FileTooLarge", http://www.downloadedBytes, signArtist.Settings.MaxFileSizeInBytes);
http://www.Dispose();
StartNextDownload(true);
yield break;
}
// Get the bytes array for the image from the webrequest and lookup the target image size for the targeted sign.
if (request.Raw)
{
imageBytes = http://www.downloadHandler.data;
}
else
{
imageBytes = GetImageBytes(www);
}
http://www.Dispose();
}
ImageSize size = GetImageSizeFor(request.Sign);
// Verify that we have image size data for the targeted sign.
if (size == null)
{
// No data was found, show a message to the player and print a detailed message to the server console and attempt to start the next download.
signArtist.SendMessage(request.Sender, "ErrorOccurred");
signArtist.PrintWarning($"Couldn't find the required image size for {request.Sign.PrefabName}, please report this in the plugin's thread.");
StartNextDownload(true);
//www.Dispose();
yield break;
}
RotateFlipType rotation = RotateFlipType.RotateNoneFlipNone;
if (request.Hor)
{
rotation = RotateFlipType.RotateNoneFlipX;
}
object rotateObj = Interface.Call("GetImageRotation", request.Sign.Entity);
if (rotateObj is RotateFlipType)
{
rotation = (RotateFlipType)rotateObj;
}
// Get the bytes array for the resized image for the targeted sign.
byte[] resizedImageBytes = imageBytes.ResizeImage(size.Width, size.Height, size.ImageWidth, size.ImageHeight, signArtist.Settings.EnforceJpeg && !request.Raw, rotation);
// Verify that the resized file doesn't exceed the maximum configured filesize.
if (resizedImageBytes.Length > signArtist.Settings.MaxFileSizeInBytes)
{
// The file is too large, show a message to the player and attempt to start the next download.
signArtist.SendMessage(request.Sender, "FileTooLarge", resizedImageBytes.Length, signArtist.Settings.MaxFileSizeInBytes);
// http://www.Dispose();
StartNextDownload(true);
yield break;
}
// Check if the sign already has a texture assigned to it.
if (request.Sign.TextureId() > 0)
{
// A texture was already assigned, remove this file to make room for the new one.
FileStorage.server.Remove(request.Sign.TextureId(), FileStorage.Type.png, request.Sign.NetId);
}
// Create the image on the filestorage and send out a network update for the sign.
request.Sign.SetImage(FileStorage.server.Store(resizedImageBytes, FileStorage.Type.png, request.Sign.NetId));
request.Sign.SendNetworkUpdate();
// Notify the player that the image was loaded.
signArtist.SendMessage(request.Sender, "ImageLoaded");
// Call the Oxide hook 'OnSignUpdated' to notify other plugins of the update event.
Interface.Oxide.CallHook("OnSignUpdated", request.Sign, request.Sender);
if (request.Sender != null)
{
// Check if logging to console is enabled.
if (signArtist.Settings.ConsoleLogging)
{
// Console logging is enabled, show a message in the server console.
signArtist.Puts(signArtist.GetTranslation("LogEntry"), request.Sender.displayName,
request.Sender.userID, request.Sign.TextureId(), request.Sign.ShortPrefabName, request.Url);
}
// Check if logging to file is enabled.
if (signArtist.Settings.FileLogging)
{
// File logging is enabled, add an entry to the logfile.
signArtist.LogToFile("log",
string.Format(signArtist.GetTranslation("LogEntry"), request.Sender.displayName,
request.Sender.userID, request.Sign.TextureId(), request.Sign.ShortPrefabName,
request.Url), signArtist);
}
if (signArtist.Settings.Discordlogging)
{
// Discord logging is enabled, add an entry to the logfile.
StartCoroutine(LogToDiscord(request));
}
}
// Attempt to start the next download.
StartNextDownload(true);
//www.Dispose();
}
Lastly change the filetoolarge warning since it gives a bit more info if you let the user know the byte size of there file vs what the limit is.
["FileTooLarge"] = "The file {0}Bytes exceeds the maximum file size of {1}Bytes.",