-
Notifications
You must be signed in to change notification settings - Fork 11
Photo Support
Photo support has been added in version version 0.6.5, however, it is very primitive. There is no direct support for retrieving images from keys, however the following methods have been added to detect the presence of photos, in order to processing on them.
gpgShowPhoto - Invokes the "show-photos" command for a given key parameters - KEYID (string)
gpgAddPhoto - Adds a (JPEG) photo to a key parameters - KEYID (string) The ID of the key to assign the photo NAME (string) The name of the image file (this is not needed anymore and will go away in new version photo_data (base64 encoded string) The base64 encoded string of the binary data
gpgGetPhotoInfo - Returns an object with information about any associated photos parameters - KEYID (string) The ID of the key to check for photos returns -
Object { 'photos_provided': 2, 'photos': { 'relative_index': 0, // The index of the image over all images 'absolute_index': 2 // The index of the image over all UIDs } }
Processing the information about photos contained in keys varies depending on your desired result.
The information returned from gpgGetPhotoInfo, and the added method gpgShowPhoto provide a means to perform various tasks such as, delete a photo from a given key, or retrieve the photos on a key (in a round-about fashion).
Photos are sort of like UIDs. They are actually User Attributes, but you can delete a photo the same way you delete a UID. Simply invoke the gpgDeleteUID method with the ID of the key, and the absolute index of the photo.
To display perform an action on a photo, you must first craft a "photo-viewer" command to handle the images. For example, to copy a photo to a given directory, you could do something like:
JavaScript
var destPath = "\"/some/place/i/stage/userphotos\""; var photoViewer = "cp %i " + destPath; pluginObject.setTempGPGOption("photo-viewer", '"' + photoViewer + '"'); pluginObject.gpgShowPhoto("012345679");
This is a fairly straight-forward example that is only relevant to Linux and OSX (using the shell), however you the photo-viewer option can be quite elaborate to derive the desired effect.
This wiki note is not geared towards the specifics of the GnuPG "photo-viewer" option, however I struggled with it for some time (on Windows), so I will include what I have learned.
The "photo-viewer" option in Windows is designed to execute a binary or script, with the option of passing various parameters to it (will add them later), due to this construct, if you attempt to use an inline script (i.e. CMD /C ...), you cannot utilize any variable that begins with "%". I believe this is due to the variable expansion in GnuPG (i.e. %i, %K). So for loops are out of the question in this regard.
For my purposes (in the WebPG browser extension), I ended up with the following JavaScript to output the associated images from a key to a specific directory with predictable file-naming:
JavaScript
var keyid = "0123456789"; var photo_info = pluginObject.gpgGetPhotoInfo(keyid); var count = photo_info.photos_provided; // Total number of photos var index = current_keylist[keyid].nuids; // Total number of UIDs (excluding photos) var path = "/some/absolute/path" var photo_viewer = []; var batch_name = "WEBPG_" + new Date().getTime() + ".bat"; // The dynamic name of the batch file_name if (window.navigator.platform.toLowerCase().indexOf("win") > -1) photo_viewer.push("cmd /V:ON /E:ON /C @SETLOCAL & @ECHO OFF & ", // Begin by creating a temporary batch file we will call later "echo @SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSION>!TEMP!\\", batch_name, " & ", "echo @ECHO OFF>>!TEMP!\\", batch_name, " & ", "echo :START>>!TEMP!\\", batch_name, " & ", "echo set \"FILEPATH=%%%1\">>!TEMP!\\", batch_name, " & ", "echo set \"FILEPATH=!FILEPATH:~1,-1!\">>!TEMP!\\", batch_name, " & ", "echo set \"INDEX=%%%2\">>!TEMP!\\", batch_name, " & ", "echo set \"PCOUNT=%%%3\">>!TEMP!\\", batch_name, " & ", "echo set \"TEMPFILE=%%%4\">>!TEMP!\\", batch_name, " & ", "echo set \"KEYID=%%%5\">>!TEMP!\\", batch_name, " & ", "echo set \"BASEFILENAME=!FILEPATH!\\!KEYID!\">>!TEMP!\\", batch_name, " & ", "echo IF NOT EXIST \"!FILEPATH!\\.\" (>>!TEMP!\\", batch_name, " & ", "echo mkdir \"!FILEPATH!\"^>null>>!TEMP!\\", batch_name, " & ", "echo )>>!TEMP!\\", batch_name, " & ", "echo IF EXIST \"!BASEFILENAME!-*.jpg\" (>>!TEMP!\\", batch_name, " & ", "echo del /Q \"!BASEFILENAME!-*.jpg\"^>null>>!TEMP!\\", batch_name, " & ", "echo )>>!TEMP!\\", batch_name, " & ", "echo copy \"!TEMPFILE!\" \"!BASEFILENAME!-latest.jpg\"^>null>>!TEMP!\\", batch_name, " & ", "echo set \"CUR=0\">>!TEMP!\\", batch_name, " & ", "echo GOTO :LOOP>>!TEMP!\\", batch_name, " & ", "echo :LOOP>>!TEMP!\\", batch_name, " & ", "echo IF NOT EXIST \"!BASEFILENAME!-!CUR!-*.j\" (>>!TEMP!\\", batch_name, " & ", "echo GOTO :END>>!TEMP!\\", batch_name, " & ", "echo ) ELSE (>>!TEMP!\\", batch_name, " & ", "echo set /A \"CUR+=1\">>!TEMP!\\", batch_name, " & ", "echo GOTO :LOOP>>!TEMP!\\", batch_name, " & ", "echo )>>!TEMP!\\", batch_name, " & ", "echo GOTO :END>>!TEMP!\\", batch_name, " & ", "echo :END>>!TEMP!\\", batch_name, " & ", "echo set /A \"POSITION=!PCOUNT!+!CUR!\">>!TEMP!\\", batch_name, " & ", "echo copy \"!BASEFILENAME!-latest.jpg\" \"!BASEFILENAME!-!CUR!-!POSITION!.j\"^>null>>!TEMP!\\", batch_name, " & ", "echo IF !CUR! equ !INDEX! (>>!TEMP!\\", batch_name, " & ", "echo rename \"!BASEFILENAME!-*.j\" \"*.jpg\"^>null>>!TEMP!\\", batch_name, " & ", "echo )>>!TEMP!\\", batch_name, " & ", // Call the batch file with the path, index, count, temporary image file (%i), // and long key id (%K), and then delete the temporary batch file. "!TEMP!\\", batch_name, " \"", path, "\" ", index, " ", count, " \"%i\" %K & del /Q !TEMP!\\", batch_name); else photo_viewer.push("FILENAME=", path, "%K; ", "if [ ! -d '", path, "' ]; then mkdir '", path, "'; fi; rm -f $FILENAME-*.jpg; cat > $FILENAME-latest.jpg", "; CUR=`ls ", path, " | awk 'BEGIN { count=0; } ~ /", key, ".*?j$/ { count++; } END { print count }'`; ", "cp $FILENAME-latest.jpg ", path, "%K-$CUR-$((", (index + 1), " + $CUR)).j; if [ $CUR -ge ", (count - 1), " ]; then for file in ", path, "*.j; do mv $file ${file}pg; done; fi;"); pluginObject.setTempGPGOption("photo-viewer", '"' + photo_viewer.join('') + '"'); pluginObject.gpgShowPhoto(key); pluginObject.restoreGPGConfig();
Regardless of the platform, the above segments will first delete any image file with the Key ID of the Key which "gpgShowPhoto" was invoked on, and then output the files in the following format: KEYID-RELATIVE_INDEX-ABSOLUTE_INDEX.jpg
For example:
/some/absolute/path/0123456789-0-2.jpg /some/absolute/path/0123456789-1-3.jpg ... and so on
Immediately after calling this method, the JS file can request the files using the Key ID, and the information returned from "gpgGetPhotoInfo".
Support other image formats when GnuPG does.