How to copy image, get path back when pasting in file input?

8

2

I sometimes get ad-hoc bug reports from customers, which I need to transfer to our online bug tracker. Works fine for text, but pictures are tedious.

I'm looking for a solution to copy-paste images from documents (like excel sheets) in a way that if you paste an image to a file input (or text input) on a html page, the file will automatically be written to disk (tmp dir), and the path written to the file input field.

This question is related to Directly paste clipboard image into gmail message, but I would like to ask if there is a solution using a local program only. I'm interested in solutions for all operating systems.

Alexander Torstling

Posted 2010-05-03T10:04:17.950

Reputation: 514

I think its not possible without third party softwares. – ukanth – 2010-05-03T10:24:24.597

Third party software is not a problem - I would just like to know if such software exists. – Alexander Torstling – 2010-05-03T10:54:34.647

If nobody finds such, I will make one.. Windows solution would be enough for me. – Pavel Radzivilovsky – 2010-06-28T10:04:04.750

1Sounds like something autohotkey could do, though I'd have to look into how. Sounds like a great idea, though. – Phoshi – 2010-06-28T10:16:06.967

Answers

3

Okay guys, This is what I did.

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace ClipSave
{
    class Program
    {
        [STAThread] public static void Main()
        {
            if (Clipboard.GetDataObject() != null)
            {
                IDataObject data = Clipboard.GetDataObject();

                if (data.GetDataPresent(DataFormats.Bitmap))
                {
                    Image image = (Image)data.GetData(DataFormats.Bitmap, true);
                    string file = System.Windows.Forms.Application.CommonAppDataPath + "\\ClipSaveImage.png";
                    image.Save(file, System.Drawing.Imaging.ImageFormat.Png);
                    Clipboard.SetText(file);

                }
                else
                    MessageBox.Show("Copy valid image first");
            }
            else
                MessageBox.Show("Copy image first");
        }
    }
}

Compiled it to an EXE, added a start-up menu shortcut to it with a hotkey Ctrl+Shift+C. It then copies the current image in clipboard to a file and puts path to the file into the clipboard.

Pavel Radzivilovsky

Posted 2010-05-03T10:04:17.950

Reputation: 188

2

This AutoHotKey thread has an AutoHotKey script for taking a screenshot. It includes the source for a trivial .Net 1.1 program to save the clipboard to a PNG. You would want it to have a few other modifications:

  • Save the image to a different folder, with a name better than image.png
  • Copy the path to the new image to your clipboard

The AutoHotKey Clipboard commands are another way to access that data, though a program to get its image data would be a bit more complicated.

Ed Brannin

Posted 2010-05-03T10:04:17.950

Reputation: 243

1

Not sure if i answering your question. but you can try out clipman. it helps you to copy everything and keep it aside until you select it back one by one. Clipman,source CNET

Jason

Posted 2010-05-03T10:04:17.950

Reputation: 39

0

  • Right click the image and save it?
  • Drag the image to a folder?
  • Use the Snipping Tool and save it from there?

These three methods will let you save a file pretty quick. The File Explorer will always go to the same folder so quickly saving or uploading the file won't be a problem either...

The direct clipboard feature has been asked before and failed.

Tamara Wijsman

Posted 2010-05-03T10:04:17.950

Reputation: 54 163

The image does not come from web. It's more than a right-click. Plus, I don't need many in a row. I need one, occasionally, for many people, at many stations. The exact use case is add a picture to fogbugz wiki. – Pavel Radzivilovsky – 2010-06-30T11:20:00.727

I don't understand this... You can just right click on an image in Word or Excel and click "Save This Picture". If the clipboard does not work, the fastest way is using one of the above methods or have someone write a add-on for Word or Excel that add a right menu option to directly upload to fogbugz. – Tamara Wijsman – 2010-06-30T20:47:37.147

0

I am not familiar with Windows, but since you asked for solutions for all OSes, I have an applescript solution for Mac OS X that I have tested by copying a picture on this website and executing the script.

This applescript assumes the image is on the clipboard in TIFF format (might have to test to see if this is what comes out of Excel.) It creates the file from the clipboard, saves it to a temporary directory, then pastes the path into a specified field on the frontmost page in Safari.

So, you would copy the image, switch to your safari page, and run the script. (From the script menu, make it into a service and assign a shortcut, or use FastScripts to assign a shortcut to the applescript.)

The script will have to be adjusted to find the proper field on your form.

repeat with i in clipboard info

  if TIFF picture is in i then

    -- grab the picture from the clipboard, set up a filename based on date
    set tp to the clipboard as TIFF picture
    set dt to current date
    set dtstr to (time of dt as string) & ".tiff"
    set pt to ((path to temporary items from user domain as string) & dtstr)
    set tf to open for access file pt with write permission

    -- save the file
    try
        write tp to tf
        close access tf
    on error
        close access tf
    end try

    -- put the path into the proper field in the web Browser
    tell application "Safari"
        activate

        -- adjust javascript as necessary
        -- currently inserts into Answer textarea of this superuser.com page for testing
        -- ie. make sure you've clicked "add answer" first
        set myJS to "document.getElementById('wmd-input').value = '" & pt & "'"

        -- document 1 is frontmost
        do JavaScript myJS in document 1
    end tell

    exit repeat
  end if
end repeat

Edit: Things to consider:

  • I do nothing with the path, default delimiter is a colon. You may want the POSIX path.
  • Is it possible to change the javascript to execute a file upload javascript? (I have no experience with this, but I think it could be done.)
  • Excel supports applescript, and has a copy picture command. It may be feasible to do this in one step. Select picture, run script, script copies, saves, opens web page and fills out the form.

ghoppe

Posted 2010-05-03T10:04:17.950

Reputation: 6 124