LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Google reverse image search from command line/Geeqie/etc with python and shell scripts

Posted 10-04-2015 at 12:43 AM by the dsc
Updated 10-04-2015 at 01:42 AM by the dsc

There's another method which consists in uploading the image from your computer in some free host and then giving this URL to google via command line, but it's kind of a scumbag-ish thing to do, I think.

Based on/essentially identical to the first answer to a question in stack overflow:

Code:
#!/usr/bin/env python
# WARNING: I DON'T KNOW PYTHON AT ALL, THIS MAY BE GRUESOME AND IDIOTIC
import sys
filePath = sys.argv[-1]

import requests

searchUrl = 'http://www.google.com/searchbyimage/upload'
multipart = {'encoded_image': (filePath, open(filePath, 'rb')), 'image_content': ''}
response = requests.post(searchUrl, files=multipart, allow_redirects=False)
fetchUrl = response.headers['Location']

import subprocess
subprocess.call([r'/usr/bin/iceweasel', fetchUrl])

# Alternatively one could have imported "webbrowser" and used a more generic "open", that 
# would probably be the system's default (as it's on stackoverflow). With this method you can 
# open firefox/iceweasel/other with certain profiles or aditional parameters:
# subprocess.call([r'/usr/bin/iceweasel', '-P myprofile', '-private-window', fetchUrl])

exit(0)
But this python script alone will just upload whatever image you have. I like the idea of not even really compromising accuracy for upload speed, with a bash script that uses imagemagick to create just an image thumbnail to use in google's search:

Code:
#!/bin/sh

convert -resize x250\> -interlace none -strip -filter Lanczos -sampling-factor 1x1 -quality 70 -- "$*" /dev/shm/googletemp$$

python gims.py /dev/shm/googletemp$$.jpg

rm /dev/shm/googletemp$$.jpg
Posted in Uncategorized
Views 3015 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 11:10 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration