Copy IMG links to Clipboard with Width and Height

2017 update: This could do with re-writing using the proper scripting and metadata APIs in newer versions of Opus.

Everything below was made before those existed, and the way it works is not recommended these days. Don't look to this post for a model way of doing anything, but you may still find what it does useful.

Purpose of the button:

Given a list of images such as this:

...this button will produce the following in the clipboard:

<img src="" width="483" height="402" alt="" />
<img src="" width="396" height="460" alt="" />
<img src="" width="396" height="460" alt="" />
<img src="" width="481" height="191" alt="" />
<img src="" width="416" height="487" alt="" />
<img src="" width="510" height="379" alt="" />
<img src="" width="510" height="379" alt="" />

This can be a huge time-saver if you are editing HTML by hand and need a list of IMG links with the correct width and height values.

Of course, the prefix is configurable.

The button will include the name of each image's parent directory in the URLs it generates. If you do not want this, see the Configuring the button section below.


The default version of the button is limited to about 500 characters, after which the clipboard string will be truncated. You can remove this limit by changing the button to use SetClip.exe. See below for details.

(This whole thing should be re-written really. Newer versions of Opus have better ways of doing everything in this post.)

Installing the button:

  • Download (2.0 KB)
  • Extract the zip file, giving you IMG links to Clipboard.dcf. (This step is important. Don't just double-click the zip to enter it. Extract it.)
  • Enter Customize mode in Opus, via Settings -> Customize Toolbars.
  • Drag the IMG links to Clipboard.dcf file to your Opus toolbar and it will turn into a button.
  • (Optional) Right-click the newly created button and select Edit, then configure it as described below.
  • Click OK in the Customize window to exit Customize mode.

You can now select some image files and click the button to put their IMG links into the clipboard.

Configuring the button:

If you install and edit the button, as described above, then you should see the following at the top:

Rename FILEINFO TO "P_{parent}|W_{picwidth}|H_{picheight}"

@script vbscript
Option Explicit

' Remove the "P_{parent}|" part in the Rename line at the top if you do not want the name
' of the parent directory to be included in the URL.

' If you want to add a prefix to the URL, set it here.
' For example, if you want to generate absolute URLs you would set something like 
' strUrlPrefix = ""
' Leave it blank if you don't want a prefix.
Dim strUrlPrefix
strUrlPrefix = ""

' If you have SetClip.exe on your machine then set fUseSetClip = True to use it instead of
' Opus's "Clipboard SET" command. Doing this enables the script to set clipboard strings
' which are bigger than the maximum command-line length.
' Get SetClip.exe from here:
Dim fUseSetClip
fUseSetClip = True

' Where to find SetClip.exe, if you have it at all. Only used if fUseSetClip is True.
Dim strSetClipPath
strSetClipPath = "C:\Windows\System32\SetClip.exe"

' Where to find DOpusRT.exe, the command used to set the clipboard if fUseSetClip is False.
Dim strOpusHomePath
strOpusHomePath = "C:\Program Files\GPSoftware\Directory Opus\DOpusRT.exe"

You can edit those values to configure the script:

  • P_{parent}:

    On the first line you'll see this:
    Rename FILEINFO TO "P_{parent}|W_{picwidth}|H_{picheight}"
    If you do not want each image's parent directory name to be included in the URLs the button generates, remove the P_{parent} part so the line looks like this:
    Rename FILEINFO TO "W_{picwidth}|H_{picheight}"

  • strUrlPrefix:

    Whatever you set strUrlPrefix to is inserted at the start of each URL that the button generates. It is blank by default. If you want to generate fully-qualified URLs then you would set strUrlPrefix to something like this:
    strUrlPrefix = ""

  • fUseSetClip:

    By default the script puts strings into the clipboard using Opus's Clipboard SET command, via DOpusRT.exe. Unfortunately, due to maximum command-line limits in Windows, this means there is a limit of about 500 characters before the clipboard string starts being truncated.

    To work around this limit, install my little SetClip and set fUseSetClip = True instead of False.

    I thought it was better for the script not to require SetClip.exe out-of-the-box but without SetClip.exe the script is limited to working with only a few files at a time.

  • strSetClipPath

    This tells the script where to find SetClip.exe. It is only used if fUseSetClip = True and it points to C:\Windows\System32\SetClip.exe by default. If you copy SetClip.exe to somewhere else then change the script.

  • strOpusHomePath

    This tells the script where to find DOpusRT.exe, which is part of Opus. It is only used if fUseSetClip = False and it points to C:\Program Files\GPSoftware\Directory Opus\DOpusRT.exe by default. If you installed Opus to a different location, and are not using SetClip.exe, then you should change this.

How the button works:

The button is actually a Rename command which uses VBScript, but it doesn't actually rename any of the files. :slight_smile: I have written a separate post, "Abusing" Rename Scripts to do other things with file info which explains this technique without the complications this button adds by having to set the clipboard.

Note that this is a bad way to do things these days. Newer versions of Opus have proper scripting almost everywhere and don't require things to be shoehorned into a Rename script when they have nothing to do with renaming. This whole button/post should be re-written, ideally. :slight_smile:

Another thing to note is that the button itself contains the rename script. There is no need to create a Rename Preset to contain the script as it is all in the button. This is good because a Rename Preset would get in your way when you actually wanted to rename some files via the Rename window.

Opus just came out and added the "Clipboard ADD SET" command which allows you to append data to the clipboard using only Opus.

However, this script has to run Opus commands via DOpusRT.exe and DOpusRT.exe runs commands asynchronously. (i.e. It doesn't wait for them to finish and two or more commands may run in parallel.) This means that there is a small chance that the script will run two Clipboard ADD SET commands at the same time, causing one of the lines will be skipped. I did a test using 5,000 files and two were skipped, so it's rare but it can happen.

Since this isn't an issue when using SetClip.exe, I have left the script as it is and still recommend using SetClip.exe unless there's a reason you can't.

This isn't to say that "Clipboard ADD SET" is useless; it's just not a good idea to use it in the way this script needs to, at least when calling it via DOpusRT.exe.

I've replaced with a new version which includes the name of each image's parent directory in the generated URLs.

For example, if your images are in a local directory called inline_images then the button will generate IMG tags like this:

<img src="inline_images/moo.jpg width="123" height="456" alt="" />

If you don't want this to happen, see the updated Configuring the button section of the main post (above).

strUrlPrefix can still be used to insert a fixed string at the start of the URL but it is now blank by default.

Really useful, thanks!

One small hickup. You're writing that [quote]By default the script puts strings into the clipboard using Opus's Clipboard SET command, via DOpusRT.exe[/quote] but when I've downloaded the script the "fUseSetClip" was set to "True". Had to change it

Oops, thanks for spotting that. I've replaced the file with one that sets fUseSetClip=False by default.

Heh, I believe that link in your post is still to the old version, with fUseSetClip=False :wink:

Isn't it meant to be false now? It was true before.

Sorry, this time mistake in my post: when I download your script from "Download" in the first post and add it to DO it's still

Dim fUseSetClip fUseSetClip = True


when I download i see the following

Try clearing your cache and download again.


when I download i see the following

[attachment=0]Clipboard Image.png[/attachment]

Try clearing your cache and download again.[/quote]
Yep, you're right, sorry for that! I wasn't aware of the cache for downloaded files. Greets

Love this button.
Broken / not compatible with the new scripting in DO11?

Works fine in Opus 11 here. (Could be written in a better way for Opus 11, but the existing one works the same as it always did.)

My bad, sorry about wasting your time.
Stupidly, I was trying it on files that were not images!...

If there's an excuse, it's that I was testing it in the same breath as checking if my (much simpler) "Copy this file name to a hyperlink" button still worked.
Don't recall if I've shared it here, so here goes.

Make a Hyperlink with this File Name

Clipboard COPYNAMES=nopaths REGEXP "(.*)" "<a href="\1" target="_blank"></a>"

Sorry again and thanks for responding.