Rename image after pasting, support name pattern and auto renaming.

Overview

Obsidian paste image rename

This plugin is inspired by Zettlr, Zettlr shows a prompt that allows the user to rename the image, this is a great help if you want your images to be named and organized clearly.

Zettlr's prompt after pasting an image

image

Paste image rename plugin not only implements Zettlr's feature, but also allows you to customize how the image name would be generated, and eventually free you from the hassle by automatically renaming the image according to the rules.

How to use

Basic usage

After installing the plugin, you can just paste an image to any document and the rename prompt will display:

By typing the new name and clicking "Rename" (or just press enter), the image will be renamed and the internal link will be replaced with the new name.

If you set "Image name pattern" to {{fileName}} (it's the default behavior after 1.2.0), "New name" will be generated as the name of the active file.

Set imageNameKey frontmatter

While adding a lot of images to one document, people possibly want the images to be named in the same format, that's where imageNameKey is useful.

First set a value for imageNameKey in frontmatter:

---
imageNameKey: my-blog
---

Then paste an image, you will notice that the "New name" has already been generated as "my-blog", which is exactly the value of imageNameKey:

You can change the pattern for new name generating by updating the "Image name pattern" value in settings.

For a detailed explanation and other features such as auto renaming, please refer to Settings.

Add prefix/suffix to duplicated names

The plugin will always try to add a prefix/suffix if there's a file of the same name.

Let's continue from the last section and paste the second image, the prompt will still show the new name as "my-blog", now if we just click "Rename", the file will be renamed as "my-blog-1.png", not "my-blog.png":

The -1 suffix is generated according to the default settings:

  • Because "Duplicate number at start" is false, suffix is used rather than prefix
  • "Duplicate number delimiter" - is put before the number 1

If we paste the third image without editing the "New name" input, its name will be "my-blog-2.png", the number is increased according to the largest number of "my-blog-?.png" in the attachment directory.

This feature is especially powerful if you enable "Auto rename" in settings, you can just add new images without thinking, and they will be renamed sequentially by the pattern and imageNameKey set.

FAQ

  • Q: I pasted an image but the rename prompt did not show up.

    A: This is probabily because you are using Windows system and pasting from a file (i.e. the image is copied from File Explorer not from a browser or image viewer). In Windows, pasting from a file is like a regular file tranfer, the original file name is kept rather than being created and named "Pasted image ..." by Obsidian. You need to turn on "Handle all image" in settings to make it work in this situation.

Settings

  • Image name pattern

    The pattern indicates how the new name should be generated.

    • Available variables:

      • {{imageNameKey}}: this variable is read from the markdown file's frontmatter, from the same key imageNameKey.
      • {{DATE:$FORMAT}}: use $FORMAT to format the current date, $FORMAT must be a Moment.js format string, e.g. {{DATE:YYYY-MM-DD}}
    • Examples of pattern to results :

      (imageNameKey = "foo")

      • {{imageNameKey}}-: foo-
      • {{imageNameKey}}-{{DATE:YYYYMMDDHHmm}}: foo-202204081652
      • Pasted Image {{DATE:YYYYMMDDHHmm}}: Pasted Image 202204081652
  • Duplicate number at start (or end)

    If enabled, the duplicate number will be added at the start as prefix for the image name, otherwise, it will be added at the end as suffix for the image name.

  • Duplicate number delimiter

    The delimiter to generate the number prefix/suffix for duplicated names. For example, if the value is -, the suffix will be like "-1", "-2", "-3", and the prefix will be like "1-", "2-", "3-".

  • Auto rename

    By default, the rename modal will always be shown to confirm before renaming, if this option is set, the image will be auto renamed after pasting.

  • Handle all images

    By default, the plugin only handles images that starts with "Pasted image " in name, which is the prefix Obsidian uses to create images from pasted content. If this option is set, the plugin will handle all images. This includes drag'n drop image, or any other image that is created in the valut.

Comments
  • FR: Command to bulk rename already existing

    FR: Command to bulk rename already existing

    I really love the consistency by this plugin and was wondering whether it's possible to add a command that renames all images link in the current note, maybe with a customizable pattern, so only images with "bad" names get renamed?

    enhancement 
    opened by chrisgrieser 10
  • Request: Extend functionality to other file types

    Request: Extend functionality to other file types

    Hi - First of all, the plugin works perfectly, thank you for the work.

    In order to increase consistency with other attachments, would it be possible to extend the functionality to other file types? E.g. pdf but also docx. or any other attachment? This would allow this plugin to become the main authority of all file name patterns and would increase the usability greatly.

    thank you for considering this.

    enhancement 
    opened by indiewelt 6
  • Bug:

    Bug: "Pasted Image" Pattern not working.

    When this toggle is off, the plugin is supposed to work with images that match "Pasted Image" if I understand this correctly? For me that is not the case. I paste an Image with the name Pasted Image 123.png into the editor and nothing happens. Only with the "Handle all images" setting enabled, does the plugin work for me.

    Pasted Image 2022-04-18 21 17 12
    opened by chrisgrieser 4
  • The regex mode dos not work? Or the syntax is with mistake?

    The regex mode dos not work? Or the syntax is with mistake?

    Describe the bug I try to use regex mode for batch renaming images. The ".+" and "png" are used, but the original file path is empty. 0 image is matched. But if I use the command "batch rename instantly", it works and renames the images in the note. The images are shown in markdown links.

    Environments (please complete the following information):

    • OS: [Windows 10, 21H2, 19044.1766]
    • Obsidian: v0.15.2(insider build)
    • Use [[Wikilinks]]: [false]
    • Debug info:

    To Reproduce Steps to reproduce the behavior:

    1. Click the command "paste image rename: batch rename embeded files (in the current file)"
    2. Type in ".+" as the name pattern. Type in "png" as the extension pattern.
    3. No image is matched.

    Expected behavior Solve the problem

    Screenshots image

    bug 
    opened by Sun-Pengcheng 1
  • pasting to a canvas doesn't trigger the plugin

    pasting to a canvas doesn't trigger the plugin

    1. Setup the plugin with default settings
    2. Create a new canvas
    3. Paste an image from the web

    Expected result: image renamed to match the canvas

    Actual result: plugin does not trigger

    bug 
    opened by nikodemus 0
  • non-ascii characters (unicode) disappear

    non-ascii characters (unicode) disappear

    Describe the bug A clear and concise description of what the bug is.

    Environments (please complete the following information):

    • OS: Windows
    • Use [[Wikilinks]]: false
    • Debug info: I can`t find command "Show debug info"

    Thank you for the wonderful plugin!! I found only one problem - if non-ascii characters (unicode) are used in the file name, then they are simply disappear (you can see in the screenshots). Please add the ability to work with unicode!

    image image

    bug 
    opened by BigbadHort 1
  • better duplicate number

    better duplicate number

    opened by irrealizable 0
  • Pasted image not prompting a dialog

    Pasted image not prompting a dialog

    Describe the bug Pasted image doesn't prompt a dialog, also turning on all attachments doesn't fix this.

    Environments (please complete the following information):

    • OS: Archlinux
    • Use [[Wikilinks]]: True (also tried false)
    • Debug info: SYSTEM INFO: Obsidian version: v1.0.3 Installer version: v1.0.3 Operating system: #1 SMP PREEMPT_DYNAMIC Thu, 03 Nov 2022 18:01:58 +0000 6.0.7-arch1-1 Login status: not logged in Insider build toggle: off Live preview: on Legacy editor: off Base theme: dark Community theme: none Snippets enabled: 1 Restricted mode: off Plugins installed: 2 Plugins enabled: 2 1: Markdown Formatting Assistant v0.4.0 2: Advanced Tables v0.17.3

    To Reproduce Steps to reproduce the behavior:

    1. Copy image to clipboard (i use Spectacle for this)
    2. Paste image into an Obsidian note

    Expected behavior A dialog prompting to rename should appear upon pasting the image

    bug 
    opened by JStyle21 2
  • 【重命名rename按钮功能经常失效,录屏为证】MD文档中,还是原来的Pasted image开头的,但是图片文件已经重命名了

    【重命名rename按钮功能经常失效,录屏为证】MD文档中,还是原来的Pasted image开头的,但是图片文件已经重命名了

    Describe the bug

    1 弹窗后,按rename按钮的行为--不符合预期 2 弹窗后,按cancel按钮的行为--符合预期 3 弹窗后,按键盘enter的行为--不符合预期

    Environments (please complete the following information):

    • OS: [Windows10 20H2 X64]
    • Use [[Wikilinks]]: [false]
    • Debug info:

    To Reproduce

    1 弹窗后,按rename按钮的行为--不符合预期

    MD文档没有成功重命名,附件图片文件已经重命名

    
    ![](img/图片重命名插件-issue-20221019.png)
    
    
    
    ![](img/图片重命名插件-issue-20221019-12.png)
    
    ![](img/Pasted%20image%2020221019122250.png)  这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    ![](img/图片重命名插件-issue-20221019-14.png)
    
    ![](img/Pasted%20image%2020221019122334.png) 这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    
    ![](img/Pasted%20image%2020221019122350.png) 这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    ![](img/图片重命名插件-issue-20221019-17.png)
    
    ![](img/Pasted%20image%2020221019122358.png) 这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    ![](img/Pasted%20image%2020221019122400.png) 这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    ![](img/Pasted%20image%2020221019122403.png) 这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    ![](img/图片重命名插件-issue-20221019-21.png)
    
    
    ![](img/图片重命名插件-issue-20221019-22.png)
    
    
    ![](img/图片重命名插件-issue-20221019-23.png)
    
    ![](img/图片重命名插件-issue-20221019-24.png)
    
    ![](img/图片重命名插件-issue-20221019-25.png)
    
    ![](img/图片重命名插件-issue-20221019-26.png)
    
    
    ![](img/图片重命名插件-issue-20221019-27.png)
    
    ![](img/Pasted%20image%2020221019122432.png) 这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    ![](img/Pasted%20image%2020221019122440.png) 这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    ![](img/Pasted%20image%2020221019122444.png) 这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    
    

    2 弹窗后,按cancel按钮的行为--符合预期

    
    MD文档是默认的,附件图片文件也是默认的,都是Pasted image开头的
    
    **操作了很多遍,都是符合预期的,cancel会采用默认的**
    
    ![](img/Pasted%20image%2020221019121731.png)
    
    
    ![](img/Pasted%20image%2020221019122150.png)
    
    ![](img/Pasted%20image%2020221019122155.png)
    
    ![](img/Pasted%20image%2020221019122159.png)
    
    ![](img/Pasted%20image%2020221019122201.png)
    
    
    ![](img/Pasted%20image%2020221019122203.png)
    
    
    ![](img/Pasted%20image%2020221019122205.png)
    
    
    ![](img/Pasted%20image%2020221019122208.png)
    
    ![](img/Pasted%20image%2020221019122209.png)
    
    ![](img/Pasted%20image%2020221019122212.png)
    
    ![](img/Pasted%20image%2020221019122214.png)
    
    

    3 弹窗后,按键盘enter的行为--不符合预期

    操作一下,粘贴图片,弹窗后,按键盘enter

    会发现,附件图片文件已经重命名,但是MD文档中,还是原来的Pasted image开头的。 这种enter按键会有很大的概率导致文档内的名称和附件图片的名称不一致

    下面演示的都是enter按键的

    
    ![](img/Pasted%20image%2020221019121854.png) 这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    ![](img/图片重命名插件-issue-20221019-2.png)
    
    ![](img/Pasted%20image%2020221019122011.png)这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    ![](img/Pasted%20image%2020221019122016.png)这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    
    ![](img/图片重命名插件-issue-20221019-5.png)
    
    
    ![](img/Pasted%20image%2020221019122100.png)这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    
    ![](img/Pasted%20image%2020221019122108.png)这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    
    ![](img/Pasted%20image%2020221019122112.png)这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    ![](img/Pasted%20image%2020221019122114.png)这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    ![](img/Pasted%20image%2020221019122115.png)这一次就没有符合预期,MD文档没有成功重命名,附件图片文件已经重命名
    
    
    ![](img/图片重命名插件-issue-20221019-11.png)
    
    
    

    4 录屏现象

    F:\Capture\bandicam 2022-10-19 12-16-50-693.mp4

    https://user-images.githubusercontent.com/19929230/196602285-5651c5bd-ccc0-46ba-9c75-dbf35e8b6eb2.mp4

    Screenshots

    image

    bug 
    opened by lxq1 0
Releases(1.5.0)
Owner
Xiao Meng
Craft and smelt.
Xiao Meng
Best dialogue for file creation, renaming, opening, deletion or jumping to a specific line

Features No need to rely on vscode.quickOpen Create, rename, delete, open files/folders without relying on the sidebar Jump to specific lines Find spe

Suryansh Makharia 3 Jul 31, 2022
jQuery-plugin for add/remove dom-items with renaming form-elements (arrays)

dynamicrows jQuery-plugin for add/remove rows by cloning existing row / renaming form-elements (arrays). Requirements jQuery >=2.0 if move-action used

Dennis Dohle 0 Nov 9, 2020
This project is created to store the name of the book and the name of its author, build with JavaScript.

awesome-books A plain javascript project that can keep track of a list of books utilizing localStorage. See live demo Built With HTML CSS Javascript T

Shaqayq Darwazi 3 Jul 19, 2022
When pasting screenshots into obsidian notes, convert the images to jpeg and compress them

obsidian-paste-png-to-jpeg This plugin is inspired by obsidian-paste-image-rename, obsidian-paste-image-rename can be used when inserting images renam

null 19 Nov 15, 2022
Trim unnecessary indentation when pasting code

Unindent When pasting code from your editor into Discord, it often ends up having a lot of indentation. This plugin fixes that by trimming unnecessary

Vens Powercord Plugins 19 May 1, 2022
Emoji - Use emoji names instead of Unicode strings. Copy-pasting emoji sucks.

Grammy Emoji Adds emoji parsing for grammY. Check out the official documentation for this plugin. While this draft is working, we still do not recomme

null 8 Sep 5, 2022
A handy little app for copying & pasting images.

PikPicPASTE A handy little app for copying & pasting images. Usage Click and drag the hamburger tile to move the toolbar Click the hamburger tile to s

null 5 Nov 1, 2022
This is a simple Image popup Jquery plugin. With a very simple configuration, you can show a popup on your webpage. By the way, this plugin works after page load.

Jquery-SingleImagePopup This is a simple Image popup Jquery plugin. With a very simple configuration, you can show a popup on your webpage. By the way

Rajan Karmaker 1 Aug 22, 2022
Types generator will help user to create TS types from JSON. Just paste your single object JSON the Types generator will auto-generate the interfaces for you. You can give a name for the root object

Types generator Types generator is a utility tool that will help User to create TS Interfaces from JSON. All you have to do is paste your single objec

Vineeth.TR 16 Dec 6, 2022
optimize image & upload file to cloud as image bed with tiny image automic.

Rush! 图片压缩 & 直传图床工具 这是一个兴趣使然的项目, 希望 Rush! 能让这个世界的网络资源浪费减少一点点 下载 Downloads 获取最新发行版 功能 Features 拖拽批量压缩图片, 支持格式 jpg/png/gif Drop to optimize, jpg/png/gif

{ Chao } 3 Nov 12, 2022
Query for CSS brower support data, combined from caniuse and MDN, including version support started and global support percentages.

css-browser-support Query for CSS browser support data, combined from caniuse and MDN, including version support started and global support percentage

Stephanie Eckles 65 Nov 2, 2022
Ethereum smart contract gas cost waste pattern detection and patching tool

Ethereum smart contract gas cost waste pattern detection and patching tool

ibelab 4 Mar 23, 2022
🌗 1 line of code to apply auto dark / light theme and support custom theme for your website. Super fast and lightweight theme library.

themes.js A super lightweight and fast Theme library with auto system color scheme detection in JavaScript. Features Auto detect Dark / Light mode by

SerKo 4 Nov 29, 2022
Cypress commands are asynchronous. It's a common pattern to use a then callback to get the value of a cypress command

cypress-thenify Rationale Cypress commands are asynchronous. It's a common pattern to use a then callback to get the value of a cypress command. Howev

Mikhail Bolotov 15 Oct 2, 2022
Implementação do Observer Pattern em TypeScript para o Código Fonte TV

Observer - Design Pattern Exemplos de implementação do Design Pattern Observer, descrito no livro Design Patterns: Elements of Reusable Object-Oriente

Gabriel Froes 11 Nov 30, 2022
Connect your Ethereum smart contract to any real world API using the oracle pattern!

Minimal Viable Oracle (MVO) - An effective way to Build your own oracle with Solidity Smart contracts cannot access off-chain data directly. This repo

Noah 9 Aug 25, 2022
An algorithm for fast 2D pattern-matching with wildcards.

pattern-match-2d.js An algorithm for fast 2D pattern-matching with wildcards, with a demo app inspired by MarkovJunior (by Maxim Gumin). The algorithm

null 16 Nov 5, 2022
A probabilistic programming language based on pattern-rewriting

MJr-compiler MJr is a probabilistic programming language based on pattern-rewriting, heavily inspired by MarkovJunior by Maxim Gumin. This project pro

Andrew Kay 35 Dec 15, 2022