Capture and Convert Images (including .webp) with Pic2File for Windows

Page content

Once Upon a Time

In 2009, I created an image capture utility for Windows called Pic2File. It wasn’t like a number of capture utilities. For Pic2File to function, images needed to be copied to the Windows clipboard. Pic2File would scan the clipboard periodically for images. If image content was present on the clipboard, it would save the image to the specified file format in a sequentially-numbered file. It then clears the clipboard data. This is important because you might forget that Pic2File is running while trying to copy data to/from the clipboard.

This permitted a couple of different handy types of image capture situations:

  • Right-click-copying images on any web page
  • Hitting PrtSc, Alt-PrtSc or any other combination of standard Windows print-screen keys

I had been using an older version of this code for a while. I made a couple of changes as I placed the code on Github… but, I ran into a few issues.

Deployment Issues

I don’t normally have a Visual Studio environment on my Windows machines. When I need to compile a CSharp program, I normally just use the built-in compiler available locally with the current .NET distribution. This is usually c:\windows\microsoft.net\framework64\v4.0.30319\csc.exe . I’ve used this approach for years because it’s easy enough to walk somebody through a local compilation. Every recent Windows machine should have this compiler ( although I don’t know if it’s present in the same spot on Windows 11).

I made my changes. I compiled and tested the code. I created a new Github repo ( https://github.com/jimlawless/pic2file/ ), placing the relevant sources there. I usually make a binary version available when I publish a utility, so I zipped up a copy and uploaded it to my web site. I tried the URL to be sure that I had it listed correctly in other references. My browser (Chrome) downloaded the file after a little coaxing. When I tried to open the .zip file, Microsoft’s Windows Defender AV tool intervened, citing that the exe contained a known virus. At that point, I could no longer use the EXE that I had previously compiled myself.

Once I compiled the code again, it worked fine. I was able to copy the EXE all over the C: drive. Once I uploaded it to my web site and tried to download it again, I had the same issue. For some reason, there was something in this binary that triggered Windows Defender once it had been downloaded from the web.

Today, I compiled the code with Mono. All seems to be fine with Windows Defender. If you get a warning from your AV by running the packaged EXE, you might need to rebuild from the sources yourself. It should be as simple as:

csc pic2file.cs assemblyinfo.cs 

…or some variant of that command line.

Using Pic2File

Pic2File is a console program. If you run it with no arguments, it will use JPEG as the output format and it will write the image files into the current directory. Here are the command line options:

  • -h simply displays the help info and exits. In fact, every operation displays the help info. -h ensures that the program doesn’t do anything else.
  • -dir accepts a directory path for the output image files.
  • -prefix accepts a string to use as a prefix for the image file names. The default is “p2f_”.
  • -beep causes the program to beep each time it writes out a new image file. The default is false ( which is the setting when -beep is omitted. )

You can also specified one of the five options to specify the preferred output format:

  • -gif
  • -png
  • -tiff
  • -jpg
  • -bmp

If you want to try out Pic2File, simply run it with no arguments in a directory where you can store some sample image files.

C:\test>pic2file

Pic2File by Jim Lawless - jimbo@radiks.net
Github source: https://github.com/jimlawless/pic2file
Blog post: https://jimlawless.net/posts/pic2file

Syntax: Pic2File.exe -dir dir_to_store_pics -prefix filename_prefix -beep [ -gif -png -tiff -jpg -bmp ]

The default output format is -jpg.


Work directory: .\
Filename prefix: p2f_
Image format: .jpg
Play beep on save: False

Waiting...

While it’s waiting, go to a web site and right-click and copy a picture. It doesn’t matter what format the picture is in ( including WEBP ) … Pic2File will save it as a JPEG file p2f_0.jpg because we took the defaults. You should see a message similar to the following:

Saving .\p2f_0.jpg ... done.

Now hit the Windows PrtSc button. You should see another message indicating that p2f_1.jpg has been saved. This works because Windows copies screen images to the clipboard when you hit various combinations of the PrtSc key and various shift/control keys. In this case, the captured area might include multiple screens if you use multiple monitors.

The files are always numbered sequentially, even after successive invocations of Pic2File. It never overwrites an existing image file.

Known Issues

  • There’s the issue with the clipboard. If you try to use it while Pic2File is running, you are probably going to run into difficulty unless you end the Pic2File process.

  • If you fill up a folder with images, it might take a while for it to save the first one. Pic2File will start with p2f_0 as a prefix and it will keep incrementing the number on the right until the file with the desired image suffix does not exist. If you have a lot of images in a folder such as p2f_0.jpg through p2f_999.jpg … it might take a while to sequentially find the next available spot. My recommendation is to use different prefixes and/or use separate folders for each type of capture session that you need.

  • Large images have presented a problem here and there. The code will display a console error message when this happens. I haven’t worked on a fix for this as it happens infrequently.

Closing

Please let me know via email ( jimbo@radiks.net ) if you run into any issues that appear to originate from Pic2File.