Added "Never Resize Avatars" option.

Changed crop dialog to have "Accept"/"Cancel" buttons.
This commit is contained in:
hh_aa
2023-06-18 17:09:10 -04:00
parent 2d97b4bd0a
commit 56656b95cf
4 changed files with 28 additions and 5 deletions

View File

@ -2167,6 +2167,9 @@
<span class="note-link-span">?</span> <span class="note-link-span">?</span>
</a> </a>
</label> </label>
<label for="never_resize_avatars"><input id="never_resize_avatars" type="checkbox" />
<span data-i18n="Never Resize Avatars">Never Resize Avatars</span>
</label>
<div id="reload_chat" class="menu_button whitespacenowrap" data-i18n="Reload Chat"> <div id="reload_chat" class="menu_button whitespacenowrap" data-i18n="Reload Chat">
Reload Chat Reload Chat

View File

@ -3617,6 +3617,9 @@ async function read_avatar_load(input) {
$('#dialogue_popup').addClass('large_dialogue_popup wide_dialogue_popup'); $('#dialogue_popup').addClass('large_dialogue_popup wide_dialogue_popup');
const croppedImage = await callPopup(getCropPopup(e.target.result), 'avatarToCrop'); const croppedImage = await callPopup(getCropPopup(e.target.result), 'avatarToCrop');
if (!croppedImage) {
return;
}
$("#avatar_load_preview").attr("src", croppedImage || e.target.result); $("#avatar_load_preview").attr("src", croppedImage || e.target.result);
@ -4868,8 +4871,8 @@ function callPopup(text, type, inputValue = '') {
$("#dialogue_popup_cancel").css("display", "inline-block"); $("#dialogue_popup_cancel").css("display", "inline-block");
switch (popup_type) { switch (popup_type) {
case "avatarToCrop": case "avatarToCrop":
$("#dialogue_popup_ok").text("Ok"); $("#dialogue_popup_ok").text("Accept");
$("#dialogue_popup_cancel").css("display", "none"); break;
case "text": case "text":
case "alternate_greeting": case "alternate_greeting":
case "char_not_selected": case "char_not_selected":
@ -4915,6 +4918,7 @@ function callPopup(text, type, inputValue = '') {
rotatable: false, rotatable: false,
crop: function (event) { crop: function (event) {
crop_data = event.detail; crop_data = event.detail;
crop_data.want_resize = !power_user.never_resize_avatars
} }
}); });
} }
@ -6025,7 +6029,10 @@ $(document).ready(function () {
}); });
$('#dialogue_popup').addClass('large_dialogue_popup wide_dialogue_popup'); $('#dialogue_popup').addClass('large_dialogue_popup wide_dialogue_popup');
await callPopup(getCropPopup(dataUrl.target.result), 'avatarToCrop'); const confirmation = await callPopup(getCropPopup(dataUrl.target.result), 'avatarToCrop');
if (!confirmation) {
return;
}
let url = "/uploaduseravatar"; let url = "/uploaduseravatar";

View File

@ -96,6 +96,7 @@ let power_user = {
avatar_style: avatar_styles.ROUND, avatar_style: avatar_styles.ROUND,
chat_display: chat_styles.DEFAULT, chat_display: chat_styles.DEFAULT,
sheld_width: sheld_width.DEFAULT, sheld_width: sheld_width.DEFAULT,
never_resize_avatars: false,
play_message_sound: false, play_message_sound: false,
play_sound_unfocused: true, play_sound_unfocused: true,
auto_save_msg_edits: false, auto_save_msg_edits: false,
@ -531,6 +532,7 @@ function loadPowerUserSettings(settings, data) {
$("#multigen_next_chunks").val(power_user.multigen_next_chunks); $("#multigen_next_chunks").val(power_user.multigen_next_chunks);
$("#play_message_sound").prop("checked", power_user.play_message_sound); $("#play_message_sound").prop("checked", power_user.play_message_sound);
$("#play_sound_unfocused").prop("checked", power_user.play_sound_unfocused); $("#play_sound_unfocused").prop("checked", power_user.play_sound_unfocused);
$("#never_resize_avatars").prop("checked", power_user.never_resize_avatars);
$("#auto_save_msg_edits").prop("checked", power_user.auto_save_msg_edits); $("#auto_save_msg_edits").prop("checked", power_user.auto_save_msg_edits);
$("#allow_name1_display").prop("checked", power_user.allow_name1_display); $("#allow_name1_display").prop("checked", power_user.allow_name1_display);
$("#allow_name2_display").prop("checked", power_user.allow_name2_display); $("#allow_name2_display").prop("checked", power_user.allow_name2_display);
@ -1077,6 +1079,11 @@ $(document).ready(() => {
$("#ui-preset-save-button").on('click', saveTheme); $("#ui-preset-save-button").on('click', saveTheme);
$("#never_resize_avatars").on('input', function () {
power_user.never_resize_avatars = !!$(this).prop('checked');
saveSettingsDebounced();
});
$("#play_message_sound").on('input', function () { $("#play_message_sound").on('input', function () {
power_user.play_message_sound = !!$(this).prop('checked'); power_user.play_message_sound = !!$(this).prop('checked');
saveSettingsDebounced(); saveSettingsDebounced();

View File

@ -1032,13 +1032,19 @@ async function charaWrite(img_url, data, target_img, response = undefined, mes =
async function tryReadImage(img_url, crop) { async function tryReadImage(img_url, crop) {
try { try {
let rawImg = await jimp.read(img_url); let rawImg = await jimp.read(img_url);
let final_width = rawImg.bitmap.width, final_height = rawImg.bitmap.height
// Apply crop if defined // Apply crop if defined
if (typeof crop == 'object' && [crop.x, crop.y, crop.width, crop.height].every(x => typeof x === 'number')) { if (typeof crop == 'object' && [crop.x, crop.y, crop.width, crop.height].every(x => typeof x === 'number')) {
rawImg = rawImg.crop(crop.x, crop.y, crop.width, crop.height); rawImg = rawImg.crop(crop.x, crop.y, crop.width, crop.height);
// Apply standard resize if requested
if (crop.want_resize) {
final_width = AVATAR_WIDTH
final_height = AVATAR_HEIGHT
}
} }
const image = await rawImg.cover(AVATAR_WIDTH, AVATAR_HEIGHT).getBufferAsync(jimp.MIME_PNG); const image = await rawImg.cover(final_width, final_height).getBufferAsync(jimp.MIME_PNG);
return image; return image;
} }
// If it's an unsupported type of image (APNG) - just read the file as buffer // If it's an unsupported type of image (APNG) - just read the file as buffer