Как вставить картинку в visual studio code
Перейти к содержимому

Как вставить картинку в visual studio code

  • автор:

How to Insert an Image in HTML Using Visual Studio Code

The following guide explains how to insert an image in HTML using Visual Studio Code.

Step 1: Put both files in the same folder

Move both the image and the .HTML document into the same folder. I have an image file named demo.png as well as an index.html file in my project folder named Test.

Same Folder

Step 2: Insert the image into the HTML code

First, open your HTML code on Visual Studio Code. It’s time to add our image within our code.

We will use the <img> tag to insert the image. Enter the following code inside the body tag (or where you want the image to be displayed):

In my case, the code will be:

IMG Tag

Next, save the file by pressing Ctrl + S.

Step 3: Run the program

Finally, we want to see our image displayed.

Click on Go Live on the bottom-right of the code console.

how to use image in visual code it's not working?

enter image description here Image is not showing in browser using the image tag where am i wrong? i want to add image in web and i am unable to do it using in visual code i don’t know where from image to be added in the URL of image so anyone guide.

Tahir Shahzad's user avatar

2 Answers 2

the problem is that your file retrieves the image based on where the html file is somewhere and it does not check the entire computer hard drive.

So if you want the problem fixed you can start from the html files location basically. So if your html file is in the src folder your img tag shall be

else if you have your html file in the signup-form folder i shall work with this

Как вставить картинку в visual studio code

Reddit and its partners use cookies and similar technologies to provide you with a better experience.

By accepting all cookies, you agree to our use of cookies to deliver and maintain our services and site, improve the quality of Reddit, personalize Reddit content and advertising, and measure the effectiveness of advertising.

By rejecting non-essential cookies, Reddit may still use certain cookies to ensure the proper functionality of our platform.

For more information, please see our Cookie Notice and our Privacy Policy .

Paste Image

Paste image directly from clipboard to markdown/asciidoc(or other file)!

Support Mac/Windows/Linux! And support config destination folder.

Now you can enable pasteImage.showFilePathConfirmInputBox to modify file path before save:

Usage

  1. capture screen to clipboard
  2. Open the command palette: Ctrl+Shift+P ( Cmd+Shift+P on Mac)
  3. Type: "Paste Image" or you can use default keyboard binding: Ctrl+Alt+V ( Cmd+Alt+V on Mac).
  4. Image will be saved in the folder that contains current editing file
  5. The relative path will be paste to current editing file

Config

The default image file name.

The value of this config will be pass to the ‘format’ function of moment library(a js time manipulation library), you can read document https://momentjs.com/docs/#/displaying/format/ for advanced usage.

And you can use variable:

  • $ : the current file name with ext.
  • $ : the current file name without ext.

Default value is Y-MM-DD-HH-mm-ss .

The destination to save image file.

You can use variable:

  • $ : the path of directory that contain current editing file.
  • $ : the path of the project opened in vscode.
  • $ : the current file name with ext.
  • $ : the current file name without ext.

The base path of image url.

You can use variable:

  • $ : the path of directory that contain current editing file.
  • $ : the path of the project opened in vscode.
  • $ : the current file name with ext.
  • $ : the current file name without ext.

Force set the file separator styel to unix style. If set false, separator styel will follow the system style.

Default is true .

The string prepend to the resolved image path before paste.

The string append to the resolved image path before paste.

How to encode image path before insert to editor. Support options:

  • none : do nothing, just insert image path to text
  • urlEncode : url encode whole image path
  • urlEncodeSpace : url encode only space character(sapce to %20)

Defalut is urlEncodeSpace .

The string prepend to the image file name.

You can use variable:

  • $ : the path of directory that contain current editing file.
  • $ : the path of the project opened in vscode.
  • $ : the current file name with ext.
  • $ : the current file name without ext.

The string append to the image name.

You can use variable:

  • $ : the path of directory that contain current editing file.
  • $ : the path of the project opened in vscode.
  • $ : the current file name with ext.
  • $ : the current file name without ext.

The pattern of string that would be pasted to text.

You can use variable:

  • $ : the image file path, with pasteImage.prefix , pasteImage.suffix , and url encoded.
  • $ : the image file path.
  • $ : the image file name with ext.
  • $ : the image file name without ext.
  • $ : the path of directory that contain current editing file.
  • $ : the path of the project opened in vscode.
  • $ : the current file name with ext.
  • $ : the current file name without ext.
  • $ : in markdown file it would be ![](https://github.com/mushanshitiancai/vscode-paste-image/raw/master/ , in asciidoc file it would be image:: , in other file it would be empty string
  • $ : in markdown file it would be ) , in asciidoc file it would be [] , in other file it would be empty string

Enabling this boolean setting will make Paste Image ask you to confirm the file path(or file name). This is useful if you want to change the file path of the image you are currently pasting. Default is false .

  • fullPath : show full path in inputBox, so you can change the path or name. Defautl value.
  • onlyName : show only file name in inputBox, so it’s easy to change name.

Config Example

I use vscode to edit my hexo blog. The folder struct like this:

I want to save all image in blog/source/img , and insert image url to article. And hexo will generate blog/source/ as the website root, so the image url shoud be like /img/xxx.png . So I can config pasteImage in blog/.vscode/setting.json like this:

If you want to save image in separate directory:

If you want to save image with article name as prefix:

If you want to use html in markdown:

Format

File name format

If you selected some text in editor, then extension will use it as the image file name. The selected text can be a sub path like subFolder/subFolder2/nameYouWant .

If not the image will be saved in this format: "Y-MM-DD-HH-mm-ss.png". You can config default image file name by pasteImage.defaultName .

File link format

When you editing a markdown, it will pasted as markdown image link format ![](https://github.com/mushanshitiancai/vscode-paste-image/raw/master/imagePath) .

When you editing a asciidoc, it will pasted as asciidoc image link format image::imagePath[] .

In other file, it just paste the image’s path.

Now you can use configuration pasteImage.insertPattern to config the fomat of file link.

Contact

If you have some any question or advice, Welcome to issue

  • [x] support win (by @kivle)
  • [x] support linux
  • [x] support use the selected text as the image name
  • [x] support config (@ysknkd in #4)
  • [x] support config relative/absolute path (@ysknkd in #4)
  • [x] support asciidoc
  • [x] supoort use variable $ and $ in config
  • [x] support config basePath
  • [x] support config forceUnixStyleSeparator
  • [x] support config prefix
  • [x] support config suffix
  • [x] supoort use variable $ and $ in config
  • [x] support check if the dest directory is a file
  • [x] support select text as a sub path with multi new directory like a/b/c/d/imageName or ../a/b/c/d/imageName
  • [x] support config default image name pattern
  • [x] support config the text format
  • [x] support file path confirm box (by @DonMartin76)

License

The extension and source are licensed under the MIT license.

Donate

If you like this plugin, you can donate to me to support me develop it better, thank you!

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *