Online Image search button

Online Image Search button


Using the imageops executable from this post Searcher.
This button
Online Image Search.dcf (5.2 KB)
extends it's capabilities using Directory Opus inbuilt conversion and resizing functions. It will support these image types bmp|gif|heic|jpg|jpeg|jfif|png|tif|tiff|webp of any size and will use the Google, Yandex and Bing image search engines to search for the selected image. The three web pages will, after a few seconds, open in your default browser with the results.

You need to edit the button script once it is placed on a toolbar and change the path at the top of the script to the location where the imageops executable has been placed (making sure to use double backslashes).

Here is the code for perusing, do not copy and paste this code, use the button dcf above as it has a modifier set which is not in this code listing.

function OnClick(clickData)
{
	var appPath = "C:\\Users\\user\\Documents\\Imgops\\imgops-windows-amd64.exe";
	var cmd = clickData.func.command;
	var source = clickData.func.sourcetab;
	var item = "";

	 if (source.stats.selitems > 1) {
		message("Too many files selected");
		return;
	}

	// one image file is selected (due to modifer in button), continue...
	item = source.selected(0);

    
	// *************************************** FUNCTIONS *************************************** 
	function CallSearch(fullPathtoImage) {
		var command = "";
		command += '"' + appPath + '" search ';
		command += '"' + fullPathtoImage + '"';
		command += ' -t ';
		// command += 'yandex,google,bing,tineye';
		command += 'yandex,google,bing';

		cmd.AddLine("@runmode:hide");
		cmd.AddLine("@nodeselect");
		cmd.AddLine("@sync:" + command);
		cmd.Run();
	}


	function is720(file) {
		return file.metadata.image.picheight <= 720
	}


	// *************************************** CONVERT TO PNG *************************************** 
	var command = "";
	if (is720(item)) { // no resize
		command += 'Image CONVERT=png AS=_temp_Directory_Opus_Image_Search.png TO "%TEMP%"';
	}
	else { // resize
		command += 'Image CONVERT=png HEIGHT=720 PRESERVEASPECTRATIO AS=_temp_Directory_Opus_Image_Search.png TO "%TEMP%"';
	}
	cmd.SetModifier("noprogress");
    cmd.RunCommand(command);


	// ************************* NEW ITEM _temp_Directory_Opus_Image_Search.png *********************
	var newItem = "%TEMP%" + "\\_temp_Directory_Opus_Image_Search.png";


	// *************************************** SEARCH ***********************************************
	CallSearch(newItem);


	// *************************************** DELETE TEMP IMAGE ************************************
    if (DOpus.FSUtil.Exists(newItem)) {
		var command = "";
        command += 'Delete ';
        command += '"' + newItem + '"';
        command += " QUIET";
        cmd.SetModifier("noprogress");
        cmd.RunCommand(command);
	}


	// *************************************** HOISTED FUNCTIONS ***************************************
	function message(txt) {
		var lister = DOpus.Listers;
		var dlg = clickData.func.Dlg;
		dlg.window = lister.lastactive;
		dlg.message = txt;
		dlg.title = "";
		dlg.buttons = "OK";
		dlg.Show;
	}


}	// *************************************** END OnClick() ***************************************

Enjoy

3 Likes