From 0295223a3d6c571609c32608156d09b0373b4c30 Mon Sep 17 00:00:00 2001 From: ShareVB Date: Sun, 15 Nov 2026 20:40:39 +0100 Subject: [PATCH] feat(new tool): Paste Image Paste an image from the clipboard with Ctrl+V or Cmd+V, or with a "Paste from clipboard" button for touch devices, then download it. - Converts to PNG (default), JPEG, or WebP, with a quality slider for JPEG and WebP. The format and quality persist across visits. - Keeps every image pasted in the session, with remove and clear all. - Shows dimensions, original and output type and size. - Edits the file name, copies the image as PNG, or copies a base64 data URL. - Converts images one at a time in the browser only. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01PEUYi3h8enZM5rmJAZ1UAF Taken from https://github.com/CorentinTh/it-tools/pull/1912/changes/d19824e7ea42a192808b585f02e2479d6fe87cb3 Co-Authored-By: @destan --- locales/en.yml | 121 ++--- src/tools/paste-image/index.ts | 24 + src/tools/paste-image/paste-image.e2e.spec.ts | 170 +++++++ .../paste-image/paste-image.service.test.ts | 132 ++++++ src/tools/paste-image/paste-image.service.ts | 230 +++++++++ src/tools/paste-image/paste-image.vue | 436 ++++++++++++++++++ 6 files changed, 1035 insertions(+), 78 deletions(-) create mode 100644 src/tools/paste-image/index.ts create mode 100644 src/tools/paste-image/paste-image.e2e.spec.ts create mode 100644 src/tools/paste-image/paste-image.service.test.ts create mode 100644 src/tools/paste-image/paste-image.service.ts create mode 100644 src/tools/paste-image/paste-image.vue diff --git a/locales/en.yml b/locales/en.yml index 17ea9246..e2c4a0bc 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -53,8 +53,7 @@ about: favorites-imported-successfully: Favorites imported successfully! error-importing-favorites-e: 'Error importing favorites: {0}' text: - collection-of-handy-online-tools-for-developers-with-great-ux-it-tools-is-a-free-and-open-source-collection-of-handy-online-tools-for-developers-and-people-working-in-it: - >- + collection-of-handy-online-tools-for-developers-with-great-ux-it-tools-is-a-free-and-open-source-collection-of-handy-online-tools-for-developers-and-people-working-in-it: >- Collection of handy online tools for developers, with great UX. IT Tools is a free and open-source collection of handy online tools for developers & people working in IT. @@ -121,8 +120,7 @@ home: themeDark: Dark page: text: - collection-of-handy-online-tools-for-developers-with-great-ux-it-tools-is-a-free-and-open-source-collection-of-handy-online-tools-for-developers-and-people-working-in-it: - >- + collection-of-handy-online-tools-for-developers-with-great-ux-it-tools-is-a-free-and-open-source-collection-of-handy-online-tools-for-developers-and-people-working-in-it: >- Collection of handy online tools for developers, with great UX. IT Tools is a free and open-source collection of handy online tools for developers & people working in IT. @@ -1596,7 +1594,7 @@ tools: label-code-snippet-to-format: 'Code snippet to format:' placeholder-put-your-code-snippet-here: Put your code snippet here label-show-line-numbers: Show line numbers - tag-: "', '" + tag-: ''', ''' tag-copy-html-formatted: Copy HTML Formatted tag-copy-code-text: Copy Code Text tag-copy-html-word: Copy to HTML/Rich text in Word @@ -2277,9 +2275,9 @@ tools: label-advanded-json-mode: Advanded JSON Mode title-prompts: Prompts placeholder-your-messages-json-array: Your 'messages' JSON array... - label-your-messages-json-array: "Your 'messages' JSON array:" + label-your-messages-json-array: 'Your ''messages'' JSON array:' placeholder-your-tools-json-array: Your 'tools' JSON array... - label-your-tools-json-array: "Your 'tools' JSON array:" + label-your-tools-json-array: 'Your ''tools'' JSON array:' title-input-json-s: Input JSON(s) placeholder-your-system-prompt-content: Your System Prompt content... label-your-system-prompt-content: 'Your System Prompt content:' @@ -2855,7 +2853,7 @@ tools: verify-description: '{0}: {1} (verify with {2})' token-secret: Token Secret token-keys: Token Keys - cannot-parse-secret-as-encoding: "Cannot parse '{0}' as '{1}': {2}" + cannot-parse-secret-as-encoding: 'Cannot parse ''{0}'' as ''{1}'': {2}' invalid-base64-string: Invalid Base64 string placeholder-input-token: Paste your JWT token to edit... click-to-input-a-existing-jwt-token-to-modify: Click to input a existing JWT token to modify @@ -4176,8 +4174,7 @@ tools: placeholder-enter-cookie-header: Enter cookie header tag-tip-navigate-to-a-website-to-test-open-f12-console-and-run: 'Tip: Navigate to a website to test, open F12 Console and run' tag-window-copy-document-cookie: window.copy(document.cookie) - tag-this-will-copy-the-cookie-string-to-your-clipboard-note-this-will-only-copy-cookies-available-to-javascript-http-only-and-secure-cookies-will-be-omitted: - >- + tag-this-will-copy-the-cookie-string-to-your-clipboard-note-this-will-only-copy-cookies-available-to-javascript-http-only-and-secure-cookies-will-be-omitted: >- . This will copy the cookie string to your clipboard. Note: This will only copy cookies available to javascript (HTTP only and secure cookies will be omitted). @@ -4381,6 +4378,7 @@ tools: label-permanent: Permanent title-generated-fw-command: 'Generated fw command:' tag-const-zone-ref: const zone = ref + tooltip-remove: Remove from this list fortune-wheel: title: Fortune wheel description: A configurable fortune wheel @@ -4869,29 +4867,25 @@ tools: label-custom-expression: 'Custom Expression:' placeholder-e-g-src-port-443-and-dst-10-0-0-1: e.g., src port 443 and dst 10.0.0.1 title-generated-tcpdump-command: Generated tcpdump command - tag-tcpdump-is-a-utility-commonly-installed-available-to-many-linux-distributions-to-quickly-gather-a-network-trace-packet-capture-in-short-it-s-the-wireshark-of-linux-to-gathering-packet-captures-tcpdump-is-very-versatile-with-many-switches-to-granularly-capture-what-you-need-to-dubug-network-traffic-with-options-to-output-results-via-console-file-or-wireshark-pcap: - >- + tag-tcpdump-is-a-utility-commonly-installed-available-to-many-linux-distributions-to-quickly-gather-a-network-trace-packet-capture-in-short-it-s-the-wireshark-of-linux-to-gathering-packet-captures-tcpdump-is-very-versatile-with-many-switches-to-granularly-capture-what-you-need-to-dubug-network-traffic-with-options-to-output-results-via-console-file-or-wireshark-pcap: >- tcpdump is a utility commonly installed / available to many Linux distributions to quickly gather a network trace / packet capture. In short, it's the wireshark of linux to gathering packet captures. tcpdump is very versatile with many switches to granularly capture what you need to dubug network traffic; with options to output results via console, file, or wireshark pcap. - tag-this-utility-is-to-help-generate-a-tcpdump-command-using-some-of-the-more-common-switches-filters-offered-by-the-tcpdump-this-utility-is-not-encompassing-of-all-options-tcpdump-offers-a-complete-list-of-options-can-be-found-via-its-manual-nbsp: - >- + tag-this-utility-is-to-help-generate-a-tcpdump-command-using-some-of-the-more-common-switches-filters-offered-by-the-tcpdump-this-utility-is-not-encompassing-of-all-options-tcpdump-offers-a-complete-list-of-options-can-be-found-via-its-manual-nbsp: >- This utility is to help generate a tcpdump command using some of the more common switches / filters offered by the tcpdump. This utility is not encompassing of all options tcpdump offers; a complete list of options can be found via its manual:  tag-https-www-tcpdump-org-manpages-tcpdump-1-html: https://www.tcpdump.org/manpages/tcpdump.1.html tag-note: 'Note:' - tag-nbsp-host-source-host-and-destination-host-can-take-multiple-entries-separate-your-entries-with-a-comma-space-or-semicolon: - >- + tag-nbsp-host-source-host-and-destination-host-can-take-multiple-entries-separate-your-entries-with-a-comma-space-or-semicolon: >-  Host, Source Host, and Destination Host can take multiple entries. Separate your entries with a comma, space, or semicolon. tag-note-2: 'Note 2:' - tag-nbsp-when-you-specify-a-source-src-or-destination-dst-flags-tcpdump-will-only-filter-in-that-direction-if-you-are-looking-to-capture-full-tcp-handshake-make-sure-you-use-host-vs-src-host-or-dst-host-to-see-both-request-and-response-flow: - >- + tag-nbsp-when-you-specify-a-source-src-or-destination-dst-flags-tcpdump-will-only-filter-in-that-direction-if-you-are-looking-to-capture-full-tcp-handshake-make-sure-you-use-host-vs-src-host-or-dst-host-to-see-both-request-and-response-flow: >-  When you specify a source (src) or destination (dst) flags, tcpdump will only filter in that direction. If you are looking to capture full TCP handshake, make sure you use "host" vs "src host" or @@ -5214,8 +5208,7 @@ tools: raid-70-requires-at-least-10-disks-with-5-minimum-per-stripe-stripes-must-contain-an-equal-number-of-disks: >- RAID 70 requires at least 10 disks with 5 minimum per stripe. Stripes must contain an equal number of disks. - raid-70-stripes-multiple-raid-7-arrays-together-raid-7-raid-0-each-raid-7-set-can-sustain-three-drive-failures: - >- + raid-70-stripes-multiple-raid-7-arrays-together-raid-7-raid-0-each-raid-7-set-can-sustain-three-drive-failures: >- RAID 70 stripes multiple RAID 7 arrays together (RAID 7 + RAID 0). Each RAID 7 set can sustain three drive failures. 2-drive-failures-per-raid-6-set: 2 drive failures per RAID 6 set @@ -5229,47 +5222,40 @@ tools: raid-50-requires-at-least-6-disks-with-3-minimum-per-stripe-stripes-must-contain-an-equal-number-of-disks: >- RAID 50 requires at least 6 disks with 3 minimum per stripe. Stripes must contain an equal number of disks. - raid-50-stripes-multiple-raid-5-arrays-together-raid-5-raid-0-each-raid-5-set-can-sustain-a-single-drive-failure: - >- + raid-50-stripes-multiple-raid-5-arrays-together-raid-5-raid-0-each-raid-5-set-can-sustain-a-single-drive-failure: >- RAID 50 stripes multiple RAID 5 arrays together (RAID 5 + RAID 0). Each RAID 5 set can sustain a single drive failure. 1-drive-failure-per-mirrored-set: 1 drive failure per mirrored set raid-10-requires-an-even-number-of-at-least-4-disks: RAID 10 requires an even number of at least 4 disks - raid-10-is-a-stripe-of-mirrors-raid-1-raid-0-each-set-of-drives-is-mirrored-and-striped-together-so-that-each-drive-in-the-set-is-fault-tolerant-within-the-group: - >- + raid-10-is-a-stripe-of-mirrors-raid-1-raid-0-each-set-of-drives-is-mirrored-and-striped-together-so-that-each-drive-in-the-set-is-fault-tolerant-within-the-group: >- RAID 10 is a stripe of mirrors (RAID 1 + RAID 0). Each set of drives is mirrored and striped together so that each drive in the set is fault tolerant within the group. 3-drive-failures: 3 drive failures raid-7-requires-at-least-5-disks: RAID 7 requires at least 5 disks - raid-7-raid-tp-non-standard-is-similiar-to-raid-5-and-raid-6-but-with-a-third-parity-block-this-allows-for-a-third-disk-failure-at-the-cost-of-storage-reduction-equal-to-three-drives: - >- + raid-7-raid-tp-non-standard-is-similiar-to-raid-5-and-raid-6-but-with-a-third-parity-block-this-allows-for-a-third-disk-failure-at-the-cost-of-storage-reduction-equal-to-three-drives: >- RAID 7/RAID TP (non-standard) is similiar to RAID 5 and RAID 6 but with a third parity block. This allows for a third disk failure at the cost of storage reduction equal to three drives. 2-drive-failures: 2 drive failures raid-6-requires-at-least-4-disks: RAID 6 requires at least 4 disks - raid-6-is-similiar-to-raid-5-but-with-an-additional-parity-block-this-allows-for-an-additional-disk-failure-at-the-cost-of-storage-reduction-equal-to-two-drives: - >- + raid-6-is-similiar-to-raid-5-but-with-an-additional-parity-block-this-allows-for-an-additional-disk-failure-at-the-cost-of-storage-reduction-equal-to-two-drives: >- RAID 6 is similiar to RAID 5 but with an additional parity block. This allows for an additional disk failure at the cost of storage reduction equal to two drives. 1-drive-failure: 1 drive failure raid-5-requires-at-least-3-disks: RAID 5 requires at least 3 disks - raid-5-uses-block-level-striping-with-parity-this-allows-for-fault-tolerance-with-a-storage-reduction-equal-to-one-drive-for-the-parity-information: - >- + raid-5-uses-block-level-striping-with-parity-this-allows-for-fault-tolerance-with-a-storage-reduction-equal-to-one-drive-for-the-parity-information: >- RAID 5 uses block level striping with parity. This allows for fault tolerance with a storage reduction equal to one drive for the parity information. raid-1-requires-at-least-1-disk: RAID 1 requires at least 1 disk - raid-1-consists-of-an-exact-copy-of-the-data-mirror-across-two-or-more-disks-the-array-will-operate-as-long-as-at-least-one-drive-is-operational: - >- + raid-1-consists-of-an-exact-copy-of-the-data-mirror-across-two-or-more-disks-the-array-will-operate-as-long-as-at-least-one-drive-is-operational: >- RAID 1 consists of an exact copy of the data (mirror) across two or more disks. The array will operate as long as at least one drive is operational. raid-0-requires-at-least-1-disk: RAID 0 requires at least 1 disk - raid-0-splits-data-evenly-across-2-or-more-disks-without-redunancy-or-fault-tolerance-creating-one-large-storage-space: - >- + raid-0-splits-data-evenly-across-2-or-more-disks-without-redunancy-or-fault-tolerance-creating-one-large-storage-space: >- RAID 0 splits data evenly across 2 or more disks without redunancy or fault tolerance creating one large storage space. categories: @@ -5411,16 +5397,14 @@ tools: text: source-wikipedia: 'Source: Wikipedia' once-the-long-break-is-finished-return-to-step-1: Once the long break is finished, return to Step 1. - keep-repeating-steps-1-3-but-after-your-4th-task-take-a-long-break-instead-of-a-short-break-20-30-minutes-is-common: - >- + keep-repeating-steps-1-3-but-after-your-4th-task-take-a-long-break-instead-of-a-short-break-20-30-minutes-is-common: >- Keep repeating Steps 1-3, but after your 4th task, take a long break instead of a short break (20-30 minutes is common). when-the-timer-rings-take-a-short-break-5-10-minutes-is-common: When the timer rings, take a short break (5-10 minutes is common). work-on-the-task-during-that-time: Work on the task during that time. decide-on-a-task-and-set-the-timer-25-minutes-is-common: Decide on a task and set the timer (25 minutes is common). five-steps-of-the-pomodoro-technique: Five steps of the Pomodoro Technique - the-pomodoro-technique-is-a-time-management-method-developed-by-francesco-cirillo-in-the-1980s-it-uses-a-timer-to-break-work-into-intervals-typically-25-minutes-in-length-separated-by-short-breaks-each-interval-is-known-as-a-pomodoro-from-the-italian-word-for-tomato-after-the-tomato-shaped-kitchen-timer-cirillo-used-as-a-university-student: - >- + the-pomodoro-technique-is-a-time-management-method-developed-by-francesco-cirillo-in-the-1980s-it-uses-a-timer-to-break-work-into-intervals-typically-25-minutes-in-length-separated-by-short-breaks-each-interval-is-known-as-a-pomodoro-from-the-italian-word-for-tomato-after-the-tomato-shaped-kitchen-timer-cirillo-used-as-a-university-student: >- The Pomodoro Technique is a time management method developed by Francesco Cirillo in the 1980s. It uses a timer to break work into intervals, typically 25 minutes in length, separated by short breaks. @@ -5632,7 +5616,7 @@ tools: service: text: invalid-octal-permissions-must-be-3-or-4-octal-digits-octalpermissions: 'Invalid octal permissions (must be 3 or 4 octal digits): {0}' - invalid-string-permissions-must-be-in-form-rwxrwxrwx-symbolicpermissions: "Invalid string permissions (must be in form 'rwxrwxrwx'): {0}" + invalid-string-permissions-must-be-in-form-rwxrwxrwx-symbolicpermissions: 'Invalid string permissions (must be in form ''rwxrwxrwx''): {0}' color-converter: title: Color converter description: Convert color between the different formats (hex, rgb, hsl and css name) @@ -5670,8 +5654,7 @@ tools: placeholder-enter-a-password: Enter a password... tag-duration-to-crack-this-password-with-brute-force: Duration to crack this password with brute force tag-note: 'Note:' - tag-the-computed-strength-is-based-on-the-time-it-would-take-to-crack-the-password-using-a-brute-force-approach-it-does-not-take-into-account-the-possibility-of-a-dictionary-attack: - >- + tag-the-computed-strength-is-based-on-the-time-it-would-take-to-crack-the-password-using-a-brute-force-approach-it-does-not-take-into-account-the-possibility-of-a-dictionary-attack: >- The computed strength is based on the time it would take to crack the password using a brute force approach, it does not take into account the possibility of a dictionary attack. @@ -5853,7 +5836,7 @@ tools: song-details: Song details twitter: text: - the-name-of-the-twitter-account-of-the-creator-ex-sharevb: "The name of the Twitter account of the creator (ex: {'@'}sharevb)..." + the-name-of-the-twitter-account-of-the-creator-ex-sharevb: 'The name of the Twitter account of the creator (ex: {''@''}sharevb)...' creator-acc: Creator acc. the-name-of-the-twitter-account-of-the-site-ex-ittoolsdottech: >- The name of the Twitter account of the site (ex: @@ -6636,20 +6619,17 @@ tools: The server either does not recognize the request method, or it lacks the ability to fulfill the request. not-implemented: Not Implemented - a-generic-error-message-given-when-an-unexpected-condition-was-encountered-and-no-more-specific-message-is-suitable: - >- + a-generic-error-message-given-when-an-unexpected-condition-was-encountered-and-no-more-specific-message-is-suitable: >- A generic error message, given when an unexpected condition was encountered and no more specific message is suitable. internal-server-error: Internal Server Error 5xx-server-error: 5xx server error - a-server-operator-has-received-a-legal-demand-to-deny-access-to-a-resource-or-to-a-set-of-resources-that-includes-the-requested-resource: - >- + a-server-operator-has-received-a-legal-demand-to-deny-access-to-a-resource-or-to-a-set-of-resources-that-includes-the-requested-resource: >- A server operator has received a legal demand to deny access to a resource or to a set of resources that includes the requested resource. unavailable-for-legal-reasons: Unavailable For Legal Reasons - the-server-is-unwilling-to-process-the-request-because-either-an-individual-header-field-or-all-the-header-fields-collectively-are-too-large: - >- + the-server-is-unwilling-to-process-the-request-because-either-an-individual-header-field-or-all-the-header-fields-collectively-are-too-large: >- The server is unwilling to process the request because either an individual header field, or all the header fields collectively, are too large. @@ -6706,8 +6686,7 @@ tools: Indicates that the resource requested is no longer available and will not be available again. gone: Gone - indicates-that-the-request-could-not-be-processed-because-of-conflict-in-the-request-such-as-an-edit-conflict: - >- + indicates-that-the-request-could-not-be-processed-because-of-conflict-in-the-request-such-as-an-edit-conflict: >- Indicates that the request could not be processed because of conflict in the request, such as an edit conflict. conflict: Conflict @@ -6715,8 +6694,7 @@ tools: request-timeout: Request Timeout the-client-must-first-authenticate-itself-with-the-proxy: The client must first authenticate itself with the proxy. proxy-authentication-required: Proxy Authentication Required - the-requested-resource-is-capable-of-generating-only-content-not-acceptable-according-to-the-accept-headers-sent-in-the-request: - >- + the-requested-resource-is-capable-of-generating-only-content-not-acceptable-according-to-the-accept-headers-sent-in-the-request: >- The requested resource is capable of generating only content not acceptable according to the Accept headers sent in the request. not-acceptable: Not Acceptable @@ -6725,19 +6703,16 @@ tools: the-requested-resource-could-not-be-found-but-may-be-available-in-the-future: >- The requested resource could not be found but may be available in the future. - the-request-was-valid-but-the-server-is-refusing-action-the-user-might-not-have-the-necessary-permissions-for-a-resource: - >- + the-request-was-valid-but-the-server-is-refusing-action-the-user-might-not-have-the-necessary-permissions-for-a-resource: >- The request was valid, but the server is refusing action. The user might not have the necessary permissions for a resource. forbidden: Forbidden - reserved-for-future-use-the-original-intention-was-that-this-code-might-be-used-as-part-of-some-form-of-digital-cash-or-micropayment-scheme: - >- + reserved-for-future-use-the-original-intention-was-that-this-code-might-be-used-as-part-of-some-form-of-digital-cash-or-micropayment-scheme: >- Reserved for future use. The original intention was that this code might be used as part of some form of digital cash or micropayment scheme. payment-required: Payment Required - similar-to-403-forbidden-but-specifically-for-use-when-authentication-is-required-and-has-failed-or-has-not-yet-been-provided: - >- + similar-to-403-forbidden-but-specifically-for-use-when-authentication-is-required-and-has-failed-or-has-not-yet-been-provided: >- Similar to 403 Forbidden, but specifically for use when authentication is required and has failed or has not yet been provided. unauthorized: Unauthorized @@ -6750,8 +6725,7 @@ tools: The request and all future requests should be repeated using another URI. permanent-redirect: Permanent Redirect - in-this-case-the-request-should-be-repeated-with-another-uri-however-future-requests-should-still-use-the-original-uri: - >- + in-this-case-the-request-should-be-repeated-with-another-uri-however-future-requests-should-still-use-the-original-uri: >- In this case, the request should be repeated with another URI; however, future requests should still use the original URI. temporary-redirect: Temporary Redirect @@ -7341,8 +7315,7 @@ tools: label-failure-probability: 'Failure Probability:' tag-key-terms-explained: 🧠 Key Terms Explained tag-raid-level: RAID Level - tag-raid-redundant-array-of-independent-disks-is-a-method-of-combining-multiple-physical-drives-into-one-logical-unit-to-improve-performance-redundancy-or-both: - >- + tag-raid-redundant-array-of-independent-disks-is-a-method-of-combining-multiple-physical-drives-into-one-logical-unit-to-improve-performance-redundancy-or-both: >- RAID (Redundant Array of Independent Disks) is a method of combining multiple physical drives into one logical unit to improve performance, redundancy, or both. @@ -7372,41 +7345,34 @@ tools: Stripe of RAID 5 arrays. Combines performance of RAID 0 with redundancy of RAID 5. tag-️-mtbf-mean-time-between-failures: ⏱️ MTBF (Mean Time Between Failures) - tag-the-average-time-in-hours-a-drive-is-expected-to-operate-before-failing-higher-mtbf-means-more-reliable-hardware: - >- + tag-the-average-time-in-hours-a-drive-is-expected-to-operate-before-failing-higher-mtbf-means-more-reliable-hardware: >- The average time (in hours) a drive is expected to operate before failing. Higher MTBF means more reliable hardware. tag-rebuild-time: 🔁 Rebuild Time - tag-the-time-required-to-reconstruct-data-on-a-replacement-drive-after-a-failure-longer-rebuild-times-increase-the-risk-of-a-second-failure-during-recovery: - >- + tag-the-time-required-to-reconstruct-data-on-a-replacement-drive-after-a-failure-longer-rebuild-times-increase-the-risk-of-a-second-failure-during-recovery: >- The time required to reconstruct data on a replacement drive after a failure. Longer rebuild times increase the risk of a second failure during recovery. tag-mttdl-mean-time-to-data-loss: 📉 MTTDL (Mean Time To Data Loss) - tag-a-statistical-estimate-of-how-long-a-raid-system-can-operate-before-data-loss-occurs-it-considers-drive-failures-rebuild-time-and-raid-redundancy-higher-mttdl-means-a-safer-system: - >- + tag-a-statistical-estimate-of-how-long-a-raid-system-can-operate-before-data-loss-occurs-it-considers-drive-failures-rebuild-time-and-raid-redundancy-higher-mttdl-means-a-safer-system: >- A statistical estimate of how long a RAID system can operate before data loss occurs. It considers drive failures, rebuild time, and RAID redundancy. Higher MTTDL means a safer system. tag-bit-error-rate-ber: 🧮 Bit Error Rate (BER) - tag-the-probability-that-a-bit-read-from-a-disk-will-be-incorrect-due-to-hardware-limitations-even-tiny-bers-like-1-in-a-trillion-can-cause-issues-during-rebuilds-especially-with-large-drives: - >- + tag-the-probability-that-a-bit-read-from-a-disk-will-be-incorrect-due-to-hardware-limitations-even-tiny-bers-like-1-in-a-trillion-can-cause-issues-during-rebuilds-especially-with-large-drives: >- The probability that a bit read from a disk will be incorrect due to hardware limitations. Even tiny BERs (like 1 in a trillion) can cause issues during rebuilds, especially with large drives. tag-unrecoverable-read-error-ure: 🧠 Unrecoverable Read Error (URE) - tag-occurs-when-a-drive-fails-to-read-a-sector-during-rebuild-ber-contributes-to-ure-risk-which-can-compromise-raid-recovery: - >- + tag-occurs-when-a-drive-fails-to-read-a-sector-during-rebuild-ber-contributes-to-ure-risk-which-can-compromise-raid-recovery: >- Occurs when a drive fails to read a sector during rebuild. BER contributes to URE risk, which can compromise RAID recovery. tag-drive-capacity-tb: 📦 Drive Capacity (TB) - tag-total-storage-per-drive-larger-drives-take-longer-to-rebuild-and-are-more-susceptible-to-ber-related-errors: - >- + tag-total-storage-per-drive-larger-drives-take-longer-to-rebuild-and-are-more-susceptible-to-ber-related-errors: >- Total storage per drive. Larger drives take longer to rebuild and are more susceptible to BER-related errors. tag-failure-probability: 📈 Failure Probability - tag-the-chance-that-the-raid-system-will-experience-data-loss-over-a-given-time-period-e-g-5-years-calculated-using-mttdl-and-exponential-failure-models: - >- + tag-the-chance-that-the-raid-system-will-experience-data-loss-over-a-given-time-period-e-g-5-years-calculated-using-mttdl-and-exponential-failure-models: >- The chance that the RAID system will experience data loss over a given time period (e.g., 5 years). Calculated using MTTDL and exponential failure models. @@ -7764,8 +7730,7 @@ tools: tag-mirrors-stripes: Mirrors/Stripes tag-reset: Reset tag-see-zpool-openzfs-cheatsheet: See Zpool/OpenZFS Cheatsheet - tag-click-on-the-section-titles-to-expand-collapse-and-view-calculated-data-hovering-over-a-table-cell-loads-the-relevant-data-into-the-calculation-values-section-below-you-can-click-table-cells-to-freeze-or-unfreeze-those-values: - >- + tag-click-on-the-section-titles-to-expand-collapse-and-view-calculated-data-hovering-over-a-table-cell-loads-the-relevant-data-into-the-calculation-values-section-below-you-can-click-table-cells-to-freeze-or-unfreeze-those-values: >- Click on the section titles to expand/collapse and view calculated data. Hovering over a table cell loads the relevant data into the Calculation Values section below. You can click table cells to freeze or unfreeze diff --git a/src/tools/paste-image/index.ts b/src/tools/paste-image/index.ts new file mode 100644 index 00000000..7007b064 --- /dev/null +++ b/src/tools/paste-image/index.ts @@ -0,0 +1,24 @@ +import { defineTool } from '../tool'; + +export const tool = defineTool({ + name: 'Paste Image', + path: '/paste-image', + description: 'Paste an image from your clipboard, convert it to PNG, JPEG, or WebP, and download it.', + keywords: [ + 'paste', + 'image', + 'clipboard', + 'download', + 'screenshot', + 'png', + 'jpeg', + 'jpg', + 'webp', + 'convert', + 'base64', + ], + component: () => import('./paste-image.vue'), + icon: defineAsyncComponent(() => import('@vicons/tabler/es/Photo')), + createdAt: new Date('2026-11-15'), + category: 'Images', +}); diff --git a/src/tools/paste-image/paste-image.e2e.spec.ts b/src/tools/paste-image/paste-image.e2e.spec.ts new file mode 100644 index 00000000..cca6ffd8 --- /dev/null +++ b/src/tools/paste-image/paste-image.e2e.spec.ts @@ -0,0 +1,170 @@ +import { type Page, expect, test } from '@playwright/test'; + +declare global { + interface Window { + createTestPng: () => Promise; + dispatchTestPaste: (items: { kind: string; type: string; getAsFile: () => File | null }[]) => void; + } +} + +const noImageWarning = 'The clipboard has no image. Copy an image, then try again.'; + +// Browsers differ in how they let scripts build a ClipboardEvent with clipboardData. +// The helpers attach the clipboard data to a plain event, which works in every browser engine. +async function installTestHelpers(page: Page) { + await page.addInitScript(() => { + window.createTestPng = async () => { + // A 2x1 PNG with one red and one transparent pixel. + const canvas = document.createElement('canvas'); + canvas.width = 2; + canvas.height = 1; + const context = canvas.getContext('2d')!; + context.fillStyle = '#ff0000'; + context.fillRect(0, 0, 1, 1); + + return new Promise((resolve) => canvas.toBlob((blob) => resolve(blob!), 'image/png')); + }; + + window.dispatchTestPaste = (items) => { + const event = new Event('paste', { bubbles: true, cancelable: true }); + Object.defineProperty(event, 'clipboardData', { value: { items } }); + (document.activeElement ?? document).dispatchEvent(event); + }; + }); +} + +// The router loads the tool lazily, so the page "load" event can fire before the tool listens for paste events. +// The tool registers its paste listener before it renders, so a visible tool button means pastes are handled. +async function waitForTool(page: Page) { + await expect(page.getByTestId('paste-from-clipboard')).toBeVisible(); +} + +async function pasteImage(page: Page) { + await page.evaluate(async () => { + const file = new File([await window.createTestPng()], 'image.png', { type: 'image/png' }); + window.dispatchTestPaste([{ kind: 'file', type: 'image/png', getAsFile: () => file }]); + }); +} + +async function pasteText(page: Page) { + await page.evaluate(() => window.dispatchTestPaste([{ kind: 'string', type: 'text/plain', getAsFile: () => null }])); +} + +test.describe('Tool - Paste image', () => { + test.beforeEach(async ({ page }) => { + await installTestHelpers(page); + await page.goto('/paste-image'); + await waitForTool(page); + }); + + test('Has title', async ({ page }) => { + await expect(page).toHaveTitle('Paste image - Toolbox'); + }); + + test('A pasted image is added to the history and can be downloaded', async ({ page }) => { + await pasteImage(page); + await pasteImage(page); + + await expect(page.getByTestId('pasted-image')).toHaveCount(2); + await expect(page.getByTestId('output-info').first()).toContainText('Output: PNG'); + + const fileNames = await page + .getByTestId('file-name') + .evaluateAll((inputs) => inputs.map((input) => (input as HTMLInputElement).value)); + expect(new Set(fileNames).size).toBe(2); + + await page.getByTestId('file-name').first().fill('my-screenshot'); + + const downloadPromise = page.waitForEvent('download'); + await page.getByTestId('download').first().click(); + const download = await downloadPromise; + + expect(download.suggestedFilename()).toBe('my-screenshot.png'); + }); + + test('The selected format converts the pasted image', async ({ page }) => { + await pasteImage(page); + await page.getByRole('button', { name: 'JPEG' }).click(); + + await expect(page.getByTestId('output-info')).toContainText('Output: JPEG'); + + const downloadPromise = page.waitForEvent('download'); + await page.getByTestId('download').click(); + const download = await downloadPromise; + + expect(download.suggestedFilename()).toMatch(/^pasted-image-\d{8}-\d{6}\.jpg$/); + }); + + test('The quality slider is shown only for lossy formats', async ({ page }) => { + await expect(page.getByText('Quality:')).toBeHidden(); + + await page.getByRole('button', { name: 'WebP' }).click(); + await expect(page.getByText('Quality:')).toBeVisible(); + + await page.getByRole('button', { name: 'PNG' }).click(); + await expect(page.getByText('Quality:')).toBeHidden(); + }); + + test('An invalid stored format falls back to PNG', async ({ page }) => { + await page.evaluate(() => localStorage.setItem('paste-image:format', 'gif')); + await page.reload(); + await waitForTool(page); + + await pasteImage(page); + + await expect(page.getByTestId('output-info')).toContainText('Output: PNG'); + }); + + test('Images can be removed one by one or all at once', async ({ page }) => { + await pasteImage(page); + await pasteImage(page); + await pasteImage(page); + await expect(page.getByTestId('pasted-image')).toHaveCount(3); + + await page.getByRole('button', { name: 'Remove' }).first().click(); + await expect(page.getByTestId('pasted-image')).toHaveCount(2); + + await page.getByRole('button', { name: 'Clear all' }).click(); + await expect(page.getByTestId('pasted-image')).toHaveCount(0); + }); + + test('Pasting text warns only outside text fields', async ({ page }) => { + await pasteImage(page); + await page.getByTestId('file-name').focus(); + await pasteText(page); + + await page.getByTestId('file-name').blur(); + await pasteText(page); + + // Only the paste outside the file name field shows the warning. + await expect(page.getByText(noImageWarning)).toHaveCount(1); + }); + + test('The paste from clipboard button adds the clipboard image', async ({ page }) => { + await page.evaluate(async () => { + const png = await window.createTestPng(); + Object.defineProperty(navigator.clipboard, 'read', { + configurable: true, + value: async () => [{ types: ['text/plain', 'image/png'], getType: async () => png }], + }); + }); + + await page.getByTestId('paste-from-clipboard').click(); + + await expect(page.getByTestId('pasted-image')).toHaveCount(1); + }); + + test('The paste from clipboard button warns when the clipboard has no image', async ({ page }) => { + await page.evaluate(() => { + Object.defineProperty(navigator.clipboard, 'read', { + configurable: true, + value: async () => [{ types: ['text/plain'], getType: async () => new Blob(['text']) }], + }); + }); + + await page.getByTestId('paste-from-clipboard').click(); + + await expect(page.getByText(noImageWarning)).toBeVisible(); + await expect(page.getByTestId('pasted-image')).toHaveCount(0); + }); +}); diff --git a/src/tools/paste-image/paste-image.service.test.ts b/src/tools/paste-image/paste-image.service.test.ts new file mode 100644 index 00000000..228e2f2e --- /dev/null +++ b/src/tools/paste-image/paste-image.service.test.ts @@ -0,0 +1,132 @@ +import { describe, expect, it } from 'vitest'; +import { + clampQuality, + convertImage, + formatSizeDelta, + getDefaultFileName, + getFileExtension, + getImageFromDataTransfer, + getTypeLabel, + getUniqueFileName, + isFallbackOutput, + isOutputFormat, +} from './paste-image.service'; + +function createDataTransfer(items: { kind: string; type: string; file?: File }[]) { + return { + items: items.map(({ kind, type, file }) => ({ kind, type, getAsFile: () => file ?? null })), + } as unknown as DataTransfer; +} + +describe('paste-image', () => { + describe('isOutputFormat', () => { + it('accepts only the supported output formats', () => { + expect(isOutputFormat('png')).toBe(true); + expect(isOutputFormat('jpeg')).toBe(true); + expect(isOutputFormat('webp')).toBe(true); + expect(isOutputFormat('gif')).toBe(false); + expect(isOutputFormat('toString')).toBe(false); + expect(isOutputFormat(undefined)).toBe(false); + }); + }); + + describe('clampQuality', () => { + it('keeps the quality between 1 and 100', () => { + expect(clampQuality(75)).toBe(75); + expect(clampQuality(0)).toBe(1); + expect(clampQuality(150)).toBe(100); + expect(clampQuality(42.6)).toBe(43); + }); + + it('falls back to the default quality for invalid values', () => { + expect(clampQuality('abc')).toBe(90); + expect(clampQuality(Number.NaN)).toBe(90); + }); + }); + + describe('getDefaultFileName', () => { + it('builds a sortable file name from the date', () => { + expect(getDefaultFileName({ date: new Date(2026, 10, 4, 9, 5, 7) })).toBe('pasted-image-20261104-090507'); + }); + }); + + describe('getUniqueFileName', () => { + it('keeps a file name that is not taken', () => { + expect(getUniqueFileName({ fileName: 'image', existingFileNames: ['other'] })).toBe('image'); + }); + + it('adds the first free numeric suffix to a taken file name', () => { + expect(getUniqueFileName({ fileName: 'image', existingFileNames: ['image'] })).toBe('image-2'); + expect(getUniqueFileName({ fileName: 'image', existingFileNames: ['image', 'image-2', 'image-3'] })).toBe( + 'image-4', + ); + }); + }); + + describe('getFileExtension', () => { + it('maps image mime types to their usual extension', () => { + expect(getFileExtension('image/png')).toBe('png'); + expect(getFileExtension('image/jpeg')).toBe('jpg'); + expect(getFileExtension('image/webp')).toBe('webp'); + expect(getFileExtension('image/svg+xml')).toBe('svg'); + }); + + it('falls back to the mime subtype for unknown image types', () => { + expect(getFileExtension('image/x-unknown+xml')).toBe('x-unknown'); + }); + }); + + describe('getTypeLabel', () => { + it('uses the output format label, or the upper-case extension for other types', () => { + expect(getTypeLabel('image/jpeg')).toBe('JPEG'); + expect(getTypeLabel('image/webp')).toBe('WebP'); + expect(getTypeLabel('image/gif')).toBe('GIF'); + }); + }); + + describe('isFallbackOutput', () => { + it('detects an output that the browser encoded in another format', () => { + expect(isFallbackOutput({ output: new Blob([], { type: 'image/png' }), format: 'webp' })).toBe(true); + expect(isFallbackOutput({ output: new Blob([], { type: 'image/webp' }), format: 'webp' })).toBe(false); + }); + }); + + describe('formatSizeDelta', () => { + it('formats the size change in percent with a sign', () => { + expect(formatSizeDelta({ originalSize: 1000, outputSize: 250 })).toBe('-75%'); + expect(formatSizeDelta({ originalSize: 1000, outputSize: 1500 })).toBe('+50%'); + expect(formatSizeDelta({ originalSize: 1000, outputSize: 1000 })).toBe('0%'); + expect(formatSizeDelta({ originalSize: 0, outputSize: 1500 })).toBe('0%'); + }); + }); + + describe('getImageFromDataTransfer', () => { + it('returns the first image file of the clipboard data', () => { + const image = new File(['image'], 'image.png', { type: 'image/png' }); + const dataTransfer = createDataTransfer([ + { kind: 'string', type: 'text/plain' }, + { kind: 'file', type: 'image/png', file: image }, + ]); + + expect(getImageFromDataTransfer(dataTransfer)).toBe(image); + }); + + it('returns undefined when the clipboard data has no image', () => { + const dataTransfer = createDataTransfer([ + { kind: 'string', type: 'text/plain' }, + { kind: 'file', type: 'application/pdf', file: new File(['pdf'], 'doc.pdf', { type: 'application/pdf' }) }, + ]); + + expect(getImageFromDataTransfer(dataTransfer)).toBeUndefined(); + expect(getImageFromDataTransfer(null)).toBeUndefined(); + }); + }); + + describe('convertImage', () => { + it('keeps the original bytes when a PNG image is converted to PNG', async () => { + const source = new Blob(['png'], { type: 'image/png' }); + + expect(await convertImage({ source, format: 'png', quality: 90 })).toBe(source); + }); + }); +}); diff --git a/src/tools/paste-image/paste-image.service.ts b/src/tools/paste-image/paste-image.service.ts new file mode 100644 index 00000000..b421f034 --- /dev/null +++ b/src/tools/paste-image/paste-image.service.ts @@ -0,0 +1,230 @@ +import { format as formatDate } from 'date-fns'; +import { getExtensionFromMimeType } from '@/composable/downloadBase64'; + +export { + outputFormats, + defaultOutputFormat, + defaultQuality, + isOutputFormat, + clampQuality, + getDefaultFileName, + getUniqueFileName, + getFileExtension, + getTypeLabel, + isFallbackOutput, + formatSizeDelta, + getImageFromDataTransfer, + readImageFromClipboard, + readImageDimensions, + convertImage, + blobToDataUrl, + writeImageToClipboard, + writeDataUrlToClipboard, +}; + +export type OutputFormat = 'png' | 'jpeg' | 'webp'; + +const outputFormats: Record = { + png: { label: 'PNG', mimeType: 'image/png', isLossy: false }, + jpeg: { label: 'JPEG', mimeType: 'image/jpeg', isLossy: true }, + webp: { label: 'WebP', mimeType: 'image/webp', isLossy: true }, +}; + +const defaultOutputFormat: OutputFormat = 'png'; +const defaultQuality = 90; + +function isOutputFormat(value: unknown): value is OutputFormat { + return typeof value === 'string' && Object.keys(outputFormats).includes(value); +} + +function clampQuality(value: unknown) { + const quality = Number(value); + + if (!Number.isFinite(quality)) { + return defaultQuality; + } + + return Math.min(100, Math.max(1, Math.round(quality))); +} + +function getDefaultFileName({ date }: { date: Date }) { + return `pasted-image-${formatDate(date, 'yyyyMMdd-HHmmss')}`; +} + +function getUniqueFileName({ fileName, existingFileNames }: { fileName: string; existingFileNames: string[] }) { + if (!existingFileNames.includes(fileName)) { + return fileName; + } + + let suffix = 2; + while (existingFileNames.includes(`${fileName}-${suffix}`)) { + suffix++; + } + + return `${fileName}-${suffix}`; +} + +function getFileExtension(mimeType: string) { + // mime-types returns "jpeg", but "jpg" is the extension most tools and people expect. + if (mimeType === 'image/jpeg') { + return 'jpg'; + } + + return getExtensionFromMimeType(mimeType) || mimeType.replace(/^image\//, '').replace(/\+.*$/, ''); +} + +function getTypeLabel(mimeType: string) { + const outputFormat = Object.values(outputFormats).find((format) => format.mimeType === mimeType); + + return outputFormat?.label ?? getFileExtension(mimeType).toUpperCase(); +} + +function isFallbackOutput({ output, format }: { output: Blob; format: OutputFormat }) { + return output.type !== outputFormats[format].mimeType; +} + +function formatSizeDelta({ originalSize, outputSize }: { originalSize: number; outputSize: number }) { + const delta = originalSize === 0 ? 0 : Math.round(((outputSize - originalSize) / originalSize) * 100); + + return `${delta > 0 ? '+' : ''}${delta}%`; +} + +function getImageFromDataTransfer(dataTransfer: Pick | null | undefined): File | undefined { + if (!dataTransfer) { + return undefined; + } + + const imageItem = Array.from(dataTransfer.items ?? []).find( + (item) => item.kind === 'file' && item.type.startsWith('image/'), + ); + + return imageItem?.getAsFile() ?? undefined; +} + +async function readImageFromClipboard(): Promise { + const clipboardItems = await navigator.clipboard.read(); + + for (const clipboardItem of clipboardItems) { + const imageType = clipboardItem.types.find((type) => type.startsWith('image/')); + + if (imageType) { + return clipboardItem.getType(imageType); + } + } + + return undefined; +} + +async function readImageDimensions(source: Blob) { + const bitmap = await createImageBitmap(source); + const { width, height } = bitmap; + bitmap.close(); + + return { width, height }; +} + +function canvasToBlob({ + canvas, + mimeType, + quality, +}: { + canvas: HTMLCanvasElement; + mimeType: string; + quality?: number; +}) { + return new Promise((resolve, reject) => { + canvas.toBlob( + (blob) => (blob ? resolve(blob) : reject(new Error('The browser could not encode the image.'))), + mimeType, + quality, + ); + }); +} + +async function convertImage({ + source, + format, + quality, +}: { + source: Blob; + format: OutputFormat; + quality: number; +}): Promise { + const { mimeType, isLossy } = outputFormats[format]; + + // Re-encoding a lossless image into the same lossless format gains nothing, so the original bytes are kept. + if (!isLossy && source.type === mimeType) { + return source; + } + + // The image is decoded only for the conversion, so the history does not keep decoded pixels in memory. + const bitmap = await createImageBitmap(source); + const canvas = document.createElement('canvas'); + + try { + canvas.width = bitmap.width; + canvas.height = bitmap.height; + + const context = canvas.getContext('2d'); + + if (!context) { + throw new Error('The browser could not create a canvas to convert the image.'); + } + + // JPEG has no alpha channel, so transparent pixels would turn black without a white background. + if (format === 'jpeg') { + context.fillStyle = '#ffffff'; + context.fillRect(0, 0, canvas.width, canvas.height); + } + + context.drawImage(bitmap, 0, 0); + bitmap.close(); + + return await canvasToBlob({ canvas, mimeType, quality: isLossy ? quality / 100 : undefined }); + } finally { + bitmap.close(); + // A zero-sized canvas releases its pixel buffer without waiting for garbage collection. + canvas.width = 0; + canvas.height = 0; + } +} + +function blobToDataUrl(blob: Blob) { + return new Promise((resolve, reject) => { + const reader = new FileReader(); + reader.onload = () => resolve(reader.result as string); + reader.onerror = () => reject(reader.error); + reader.readAsDataURL(blob); + }); +} + +function canWriteClipboardItems() { + return typeof ClipboardItem !== 'undefined' && typeof navigator.clipboard?.write === 'function'; +} + +// Each value goes into the ClipboardItem as an unresolved promise. +// Safari rejects the write once an await before it has consumed the user gesture. + +async function writeImageToClipboard({ source }: { source: Blob }) { + // Browsers only guarantee clipboard support for PNG images. + const pngBlob = convertImage({ source, format: 'png', quality: 100 }); + + await navigator.clipboard.write([new ClipboardItem({ 'image/png': pngBlob })]); +} + +async function writeDataUrlToClipboard({ + source, + writeText, +}: { + source: Blob; + writeText: (text: string) => Promise; +}) { + if (!canWriteClipboardItems()) { + await writeText(await blobToDataUrl(source)); + return; + } + + const textBlob = blobToDataUrl(source).then((dataUrl) => new Blob([dataUrl], { type: 'text/plain' })); + + await navigator.clipboard.write([new ClipboardItem({ 'text/plain': textBlob })]); +} diff --git a/src/tools/paste-image/paste-image.vue b/src/tools/paste-image/paste-image.vue new file mode 100644 index 00000000..d514186a --- /dev/null +++ b/src/tools/paste-image/paste-image.vue @@ -0,0 +1,436 @@ + + + + +