 |
Blog image capture
Blogs and news sites that have pictures to go along with stories are more entertaining to read. Often a suitable image is available on the site you're referencing, but if you only have a couple of minutes to make a post, going to the trouble of taking a screen capture, opening your graphics program, pasting it, cropping and resizing it, uploading it to your website, and then getting it into your blog post... well, you get the idea: It's a lot of effort.
I've been meaning to write an application to solve this problem for a couple of years, so it feels great to have finally done it.
Current functionality
  | The user presses the "Print Screen" button. |
  | The text "Blog Image Capture" appears in the top left corner of the screen to indicate that the program is ready for the user's selection. |
  | The user draws a bounding box around the part of the screen they'd like to capture and presses ENTER to confirm their selection. |
  | A text box appears in the top left corner of the screen for the user to enter the desired width of the image in pixels. It has the keyboard focus and the default value is selected, so the user doesn't need to click on it or erase the current value before typing in a new one. If the existing value is satisfactory, the user can simply press TAB. |
  | The text box just to the right allows the user to specify a file name. If no extension is specified, ".png" will be appended to the value in the text box when it loses focus. Otherwise, if the user specifies an extension, it will be used. The two options are ".png" and ".jpg". |
  | After pressing ENTER, the program saves the newly resized image file to the requested file name and uploads it via FTP to the website's image directory. It then sets the image of the previously created blog post to this image. |
Cost analysis
  | Press "Print Screen": 1 keystroke |
  | Draw a bounding box: 1 click + 1 mouse movement |
  | Type the desired image size: Type short value |
  | Press TAB: 1 keystroke |
  | Enter a filename: Type short value |
  | Press ENTER: 1 keystroke |
  | Total: 3x keystrokes + 1x click + 1x mouse movement + 2x type short values |
  | Typical usage time: 15 seconds |
How it works
The application runs in the background and checks once a second to see whether the clipboard contains an image. If it does, it checks the size of the image. If the size of the image isn't the size of the screen resolution, it goes into a mode whereby it only checks the clipboard once every 4 seconds so that it isn't putting a sigificant drain on the CPU grabbing the clipboard contents once each second. However, if the image is the size of the current screen resolution, it proceeds to check whether the image is the same as the previous screenshot that was processed. (If there was one) It does this by comparing a matrix of pixel samples the size of the screen, with each sample separated 100 pixels from its neighbours. It does this rather than comparing the entire images, since again, that would be prohibitively expensive.
If it's a new screenshot, or if there wasn't a previous screenshot to compare against, the program displays a window without any borders the size of the entire screen and puts the screenshot within it. Thus, the user doesn't see anything change. It also puts a label in the top left corner to indicate that the program is awaiting the user's selection.
The rest of the implementation is pretty straightforward.
Future functionality
The typical usage time could be reduced far below 15 seconds by making the following changes:
1. | Implement a simple edge detection algorithm so that the user could simply click on the image rather than drawing a bounding box around it. |
2. | Default the image size to 100 pixels since that is what I typically use. This would eliminate the need to change the image size except for rare cases. |
3. | Default the filename using the title of the most recent blog post. For example, if the blog post name was "Blog Image Capture", use "blog_image_capture.png". This would eliminate the need to specify an image filename except for rare cases. |
4. | Right now the application doesn't hide itself while uploading the image, but the user is effectively done with it, so there is no need to make the user wait around for the image upload to complete. If the upload failed for any reason, the form could re-display itself with the error message. |
5. | If the above four steps were done, that simplifies the process to pressing "Print Screen" and clicking on the image. If the user wanted to change any of the options, perhaps they could Ctrl-click the image. |
This could reduce the typical usage time to about 3 seconds.
|
|
 |