Skip to content

Build your personal knowledge base with Trilium Notes

client/image compression tool: integrate into the attachments list

Adorian Doran3bd1aa3f35dc
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 537cfcb45a..eb8f7fd4a7 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1117,7 +1117,6 @@
"convert_format_warning_risky": "You are converting between two formats that don't have identical capabilities, so some formatting may be lost and some unsupported elements may be dropped.<br><br>Do you fully assume this risk and want to proceed with the conversion?<br><br>A revision of the current note will be saved beforehand, so you can revert to the original format.",
"convert_to_markdown_successful": "Note has been converted to Markdown.",
"convert_to_text_successful": "Note has been converted to a text note.",
- "compress_images": "Compress images",
"print_pdf": "Export as PDF...",
"export_as_image": "Export as image",
"export_as_image_png": "PNG (raster)",
@@ -2451,6 +2450,8 @@
},
"open-help-page": "Open help page",
"show-help": "Show help",
+ "compress-images": "Compress images",
+ "compress-image": "Compress image",
"find": {
"case_sensitive": "Case sensitive",
"match_words": "Match words",
@@ -2911,7 +2912,6 @@
"status_deleted": "{{size}} in deleted notes and attachments",
"status_deleted_hint": "Space still held by deleted notes and by deleted attachments (whose note may still exist); erasing them reclaims it",
"menu_show_details": "Show details",
- "menu_compress_images": "Compress images",
"menu_erase_deleted": "Erase deleted data",
"erase_deleted_message": "Deleted data has been erased.",
"revisions_limit_required": "Excess snapshots can only be erased once a maximum number of revision snapshots per note is set. Without a limit, no snapshot counts as excess. Do you want to set the limit now?",
@@ -2936,7 +2936,6 @@
"cleanup_confirm_compacting_title": "Compacting database is a slow operation",
"cleanup_confirm_compacting": "Compacting the database can take several minutes, depending on its size and on the performance of the machine running Trilium. Also, up to {{space}} of free disk space on the machine is temporarily needed (in the data directory and the system's temporary directory).",
"cleanup_compact_notice": "This operation may take several minutes and Trilium will not respond until it completes.",
- "compress_title": "Compress images",
"compress_summary_reading": "Reading…",
"compress_summary_failed": "Could not read what is here.",
"compress_summary_scope_one": "{{title}}, {{count}} descendant note",
@@ -2976,7 +2975,6 @@
"compress_process_child_notes": "Process child notes as well",
"compress_process_child_notes_help": "Compresses the images of every note in the subtree, not just the selected one. Beware that a child note may be a clone, in which case its images are shared with the other notes it appears in.",
"compress_cancel": "Cancel",
- "compress_run": "Compress images",
"compress_running": "Compressing images…",
"compress_result_one": "{{count}} image processed, reducing the size from {{before}} to {{after}}.",
"compress_result_other": "{{count}} images processed, reducing the size from {{before}} to {{after}}.",
diff --git a/apps/client/src/widgets/type_widgets/Attachment.tsx b/apps/client/src/widgets/type_widgets/Attachment.tsx
index f98981383a..60b996664c 100644
--- a/apps/client/src/widgets/type_widgets/Attachment.tsx
+++ b/apps/client/src/widgets/type_widgets/Attachment.tsx
@@ -20,6 +20,7 @@ import server from "../../services/server";
import toast from "../../services/toast";
import utils from "../../services/utils";
import ws from "../../services/ws";
+import ActionButton from "../react/ActionButton";
import Admonition from "../react/Admonition";
import Button from "../react/Button";
import Dropdown from "../react/Dropdown";
@@ -35,6 +36,7 @@ import { ParentComponent, refToJQuerySelector } from "../react/react_utils";
import SiblingNavigator from "../react/SiblingNavigator";
import { TextPreview } from "./File";
import MediaPreview from "./file/MediaPreview";
+import { showImageCompressionDialog } from "./options/content_manager/space_usage/image_compression_dialog";
import { TypeWidgetProps } from "./type_widget";
/**
@@ -94,6 +96,12 @@ function AttachmentListHeader({ noteId }: { noteId: string }) {
onClick={() => parentComponent?.triggerCommand("showUploadAttachmentsDialog", { noteId })}
/>
&nbsp;
+ <ActionButton
+ icon="bx bx-collapse-alt"
+ text={t("compress-images")}
+ onClick={() => void showImageCompressionDialog({ type: "note", noteId })}
+ />
+ &nbsp;
<HelpButton
helpPage="0vhv7lsOLy82"
title={t("attachment_list.open_help_page")}
@@ -390,6 +398,16 @@ function AttachmentActions({ attachment, copyAttachmentReferenceToClipboard, onS
>{t("attachments_actions.delete_attachment")}</FormListItem>
<FormDropdownDivider />
+ {attachment.role === "image" && (
+ <FormListItem
+ icon="bx bx-collapse-alt"
+ onClick={() => void showImageCompressionDialog({
+ type: "attachment",
+ attachmentId: attachment.attachmentId,
+ mime: attachment.mime
+ })}
+ >{t("compress-image")}</FormListItem>
+ )}
<FormListItem
icon="bx bx-note"
onClick={async () => {