-
-
Notifications
You must be signed in to change notification settings - Fork 198
Add support for loading image from stdin #414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hmm, passing the path to the image without any flag should work just like using -e (ksnip -e /tmp/img.png ist same as ksnip /tmp/img.png) but that might not be working with stdout or at least I have never tested it. If it doesnβt work we can have a look at it but canβt promise any timeframe for it.
β¦________________________________
From: Tumeo <[email protected]>
Sent: Monday, August 24, 2020 6:48:00 PM
To: ksnip/ksnip <[email protected]>
Cc: Subscribed <[email protected]>
Subject: [ksnip/ksnip] Add support for stdin when using -e/--edit (#414)
Hello, I have been using ksnip for a while, but I use it only as a quick editor.
I often generate images using some programs that have support for dumping the image directly into stdout and I would like to use ksnip to edit those images.
For now, I am using mktemp as a workaround, but ksnip does not allow saving it to a new file using the default filename template.
I tried to search for related docs and found nothing about this feature (I also tried to run ksnip - and ksnip -e -).
β
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<#414>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ADBUCTFLQO5VYGDACMPJE7TSCKDTBANCNFSM4QJUS5JA>.
|
Maybe I got your feature request wrong. You would like to skip creating a temporary file and pass the image (not the path to the image) to ksnip and ksnip should open it up as a new image just as if you created a screenshot with knsip (the image should be shown ad not saved without a path)?
My previous comment is also not correct, passing the path to image as single parameter works like the -f flag, not the -e flag. The -e flag is only relevant for taking screenshots currently.
β¦________________________________
From: Damir Porobic <[email protected]>
Sent: Monday, August 24, 2020 7:59:39 PM
To: ksnip/ksnip <[email protected]>; ksnip/ksnip <[email protected]>
Cc: Subscribed <[email protected]>
Subject: Re: [ksnip/ksnip] Add support for stdin when using -e/--edit (#414)
Hmm, passing the path to the image without any flag should work just like using -e (ksnip -e /tmp/img.png ist same as ksnip /tmp/img.png) but that might not be working with stdout or at least I have never tested it. If it doesnβt work we can have a look at it but canβt promise any timeframe for it.
________________________________
From: Tumeo <[email protected]>
Sent: Monday, August 24, 2020 6:48:00 PM
To: ksnip/ksnip <[email protected]>
Cc: Subscribed <[email protected]>
Subject: [ksnip/ksnip] Add support for stdin when using -e/--edit (#414)
Hello, I have been using ksnip for a while, but I use it only as a quick editor.
I often generate images using some programs that have support for dumping the image directly into stdout and I would like to use ksnip to edit those images.
For now, I am using mktemp as a workaround, but ksnip does not allow saving it to a new file using the default filename template.
I tried to search for related docs and found nothing about this feature (I also tried to run ksnip - and ksnip -e -).
β
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub<#414>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ADBUCTFLQO5VYGDACMPJE7TSCKDTBANCNFSM4QJUS5JA>.
|
Yes, exactly!
Hm? Isn't the -f flag for --fullscreen? I tried using -e with any image path and it works the same way as passing the image path as a single parameter. |
Ok, forgot my previous comment, Iβm writing from my mobile and from my memory which seems to be not correct. I donβt use the cli interface very often.
What is the simplest setup to test your scenario? What application do I need to use to export the image?
β¦________________________________
From: Tumeo <[email protected]>
Sent: Monday, August 24, 2020 8:30:39 PM
To: ksnip/ksnip <[email protected]>
Cc: Damir Porobic <[email protected]>; Comment <[email protected]>
Subject: Re: [ksnip/ksnip] Add support for stdin when using -e/--edit (#414)
You would like to skip creating a temporary file and pass the image (not the path to the image) to ksnip and ksnip should open it up as a new image just as if you created a screenshot with knsip (the image should be shown ad not saved without a path)?
Yes, exactly!
My previous comment is also not correct, passing the path to image as single parameter works like the -f flag, not the -e flag. The -e flag is only relevant for taking screenshots currently.
Hm? Isn't the -f flag for --fullscreen? I tried using -e with any image path and it works the same way as passing the image path as a single parameter.
β
You are receiving this because you commented.
Reply to this email directly, view it on GitHub<#414 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/ADBUCTBDR7NMCD32JCQAJATSCKPT7ANCNFSM4QJUS5JA>.
|
I think the simplest setup is to use image magick commands:
|
Thanks, we'll into it but as said, can't promise any time frame. |
No problem, take your time. |
Hi, I had some free time today, so I tried to deal with it a little bit (although I'm not good with C++ and Qt). I implemented it using this info as reference: https://stackoverflow.com/questions/25711302/how-to-read-stdin-to-end-in-qt/25715691#25715691 I cannot open a PR because I cannot confirm that the code is 100% correct, but I will paste the diff/patch here, so that I can help you in some way: diff --git a/src/bootstrapper/StandAloneBootstrapper.cpp b/src/bootstrapper/StandAloneBootstrapper.cpp
index 32c9667..8bfe0e9 100644
--- a/src/bootstrapper/StandAloneBootstrapper.cpp
+++ b/src/bootstrapper/StandAloneBootstrapper.cpp
@@ -17,6 +17,7 @@
* Boston, MA 02110-1301, USA.
*/
+#include <iostream>
#include "StandAloneBootstrapper.h"
StandAloneBootstrapper::StandAloneBootstrapper() :
@@ -122,7 +123,20 @@ CaptureModes StandAloneBootstrapper::getCaptureMode() const
int StandAloneBootstrapper::startKsnipAndEditImage(const QApplication &app)
{
auto pathToImage = getImagePath();
- QPixmap pixmap(pathToImage);
+ QPixmap pixmap;
+ if (pathToImage == "-") {
+ qWarning("Reading image from stdin.");
+ QByteArray stdinImage;
+ while(!std::cin.eof()) {
+ char arr[1024];
+ std::cin.read(arr, sizeof(arr));
+ int s = std::cin.gcount();
+ stdinImage.append(arr, s);
+ }
+ pixmap.loadFromData(stdinImage);
+ } else {
+ pixmap = QPixmap(pathToImage);
+ }
if (pixmap.isNull()) {
qWarning("Unable to open image file %s.", qPrintable(pathToImage)); |
Thanks for providing this, it will definitely speed up the implementation. I'll plan it for |
This has been implemented. Thanks for providing the logic for this feature! |
This works for me, but when I run ksnip as a single instance, it fails the second time. # Opens ksnip, works as expected
convert logo: - | ksnip -e - &
# Fails with `Warning: Unable to open image file -.`
convert logo: - | ksnip -e - & When I disable running as a single instance it works as expected, however I'd loose the nice tabbed interface. |
@yetifrisstlama this issue should be fixed now. |
Hello, I have been using ksnip for a while, but I use it only as a quick editor.
I often generate images using some programs that have support for dumping the image directly into stdout and I would like to use ksnip to edit those images.
For now, I am using
mktemp
as a workaround, but ksnip does not allow saving it to a new file using the default filename template.I tried to search for related docs and found nothing about this feature (I also tried to run
ksnip -
andksnip -e -
).The text was updated successfully, but these errors were encountered: