flameshot-org / flameshot

Powerful yet simple to use screenshot software :desktop_computer: :camera_flash:
https://flameshot.org
GNU General Public License v3.0
24.07k stars 1.53k forks source link

Google Image Search #1923

Open Kolpixx opened 2 years ago

Kolpixx commented 2 years ago

On Google you can upload Images and search for similar images on the web. Lightshot has the feature that you can click on a button to search the image on google it would be nice if flameshot can add this too :D

a Button like this:

image

mmahmoudian commented 2 years ago

I personally think it is a niche use case as the user can copy the screenshot and paste it into their browser. One can perhaps use some CLI piping to achieve this fairly quickly.

I believe a better addition can be a Lua API or something similar that people can write extensions for Flameshot.

mohad12211 commented 2 years ago

working on a lua api would be absolutely amazing!

mmahmoudian commented 2 years ago

@veracioux considering that you know the codebase very well, how easy/complicated it is to implement some sort of API? I remember many moons ago there was a brief discussion with @borgmanJeremy about this but I cannot find it.

In general I think API would help in keeping Flameshot light and yet extensible so that users' creativity can also flourish.

veracioux commented 2 years ago

@mmahmoudian I don't have any experience with creating plugin APIs, so I can't weigh in :/

kpcee commented 2 years ago

A very special wish, instead of adding something like this I would extend the shortcuts, so that the user can start own bash scripts / programs on request and everyone can fulfill the most unusual wishes themselves.

mmahmoudian commented 2 years ago

@kpcee If I want to be nitpicky, I would disagree for the bash part as Bash is not yet "universal". Windows doesn't have it and MacOS has moved to ZSH. Lua on the other hand is designed for this, plus more and more software are embracing it including (I added links to their scripting documentation):

To see a more comprehensive list, check out https://en.wikipedia.org/wiki/List_of_applications_using_Lua

The good thing about having an API in general is that we can keep Flameshot thin and slim and users can bloat it as much as they want. Initially an API can support only pushing the image out and allows post-processing (e.g using lua-vips, or lua-imagick) and custom uploads.

So basically each userscript can add a button among the tools that when pressed, it allows the script to fetch the image as a [lua] object and then user can do whatever they want including image-processing, uploading, emailing, ...

kpcee commented 2 years ago

Lua on the other hand is designed for this, plus more and more software are embracing it including (I added links to their scripting documentation):

Yes I know Lua, have already made some scripts for mpv and must say that the syntax is terrible. Who has C/C++ knowledge will have to read in, because some things are different and especially unintuitive. Comments are instead of "//" or "#" two "--" and when concatenate strings not like everywhere usual "+" is used, but "..". With numbers, on the other hand, the "+" is used again. Instead of checking for NULL (nullptr) as in C/C++, a whole new name called "nil" is used in Lua.

I would guess that 99% of all users will be overwhelmed to write their own scripts, especially when it comes to send data to a server. Besides, what would most users do with a Lua script? They would most likely just call an external program or script that does the processing. Nobody would handle Lua itself, because the language offers nothing that could be used for image manipulation or you have to deal with additional libraries.

If I want to be nitpicky, I would disagree for the bash part as Bash is not yet "universal". Windows doesn't have it and MacOS has moved to ZSH.

A bash script aka shell script is a plain text file, the only difference is that the execute permission is set to true. Such files can be executed under any shell and under any operating system. Another advantage is that you can execute programs or self written scripts without to having to deal with Lua first. For example, the desired function to upload images to Google could be realized with this one-liner, you would only have to forward the return value to the browser.

curl -i -F sch=sch -F encoded_image=@path/to/my/imagefile.jpg https://www.google.com/searchbyimage/upload Source: How to use google search by image in curl

It can't be easier. That is at least my opinion, but everyone must decide for himself.

mmahmoudian commented 2 years ago

@kpcee I'm not that passionate about Lua, but I'm passionate about making Flameshot extensible so that many of the feature requests can be handled by extensions/plugins and we can keep Flameshot closer to its core. Also I'm interested to see what people can make it do when they have a nice playground to play in.

because some things are different and especially unintuitive

Of course, because it is a different language. I'm not that fluent in Lua either.

checking for NULL (nullptr) as in C/C++, a whole new name called "nil" is used in Lua.

in Lisp and eLisp (what Emacs uses) it is also nil

I would guess that 99% of all users will be overwhelmed to write their own scripts

I agree, 99% of our users will not write the extensions, but for that 1% we can have a dedicated extension repository and they can submit their code to our repo and those 99% can simply just use it. The same way that in Flameshot (assuming the user-base of Flameshot is equal to number of stars 14.5k) only 0.062% of it's user base is contributing to the whole code and the rest of 99.93% are happily utilizing it in their daily life 😉

because the language offers nothing that could be used for image manipulation or you have to deal with additional libraries.

Any language is like that and you should add libraries/packages/crates yourself: C, C++, Python, R, Julia, Rust, ...

A bash script aka shell script is a plain text file, the only difference is that the execute permission is set to true

Any interpreted language is exactly that (e.g Perl, Python, R, Lua): image

kpcee commented 2 years ago

I'm not that passionate about Lua, but I'm passionate about making Flameshot extensible so that many of the feature requests can be handled by extensions/plugins and we can keep Flameshot closer to its core. Also I'm interested to see what people can make it do when they have a nice playground to play in.

Give me just one useful example of what you can do with Lua but not with a call of a shell script / program? I can not think of any, except that you have a lot of new dependencies, more work for the devs and it makes the users more time-consuming and they must first learn Lua. if you want to add effects / fancy stuff, resize, copy, move, delete, upload … the picture, just use a simple shell script or write an complex program that you can execute. Flameshot has only to save the image first and give the shell script the location, the rest is done by the shell script / program.

The installation in Flameshot would also be a piece of cake, the call of the shell script would only consist of this call:

        QProcess *process = new QProcess();
        connect( process, SIGNAL( finished( int ) ), process, SLOT( deleteLater() ) );
        process->start(ShellScript, QStringList() << Path);

With this we are basically already finished in Flameshot, we have only to save temporarily the picture before and of course you would have to integrate the function so that the users can use it comfortably but basically that's it.

veracioux commented 2 years ago

@kpcee

Give me just one useful example of what you can do with Lua but not with a call of a shell script / program?

You are right. Both are Turing complete so you can do anything with both languages. Bash may be more accessible to users than Lua, but it is terribly ugly and inconvenient whenever you want to do something remotely complex. So the right question is not whether you can do everything with both languages, but what you can do without getting frustrated.

I do agree that buttons that run custom shell scripts would be useful. And we already have a shell API: namely the CLI options. Whether the buttons should be added to vanilla flameshot, I am not sure. But definitely make a plugin that allows that (Lua or python or otherwise).

kpcee commented 2 years ago

If you think that Lua is the right choice, then go for it. It's just my personal opinion and I don't belong to the project. :wink: Just for me, I would never use Lua for complex things, I also guess that most of the more complicated things would be realized via Python, Perl etc. because they are widely used.

Quacken8 commented 2 years ago

@Phalelashvili has been working on this function in the past