resurrecting-open-source-projects / scrot

SCReenshOT - command line screen capture utility
Other
495 stars 49 forks source link

Saving to `./-` does not work #241

Closed N-R-K closed 1 year ago

N-R-K commented 1 year ago
[scrot master]~> ./src/scrot ./-
scrot: Saving to file ./- failed: No such file or directory
[scrot master]~> ./src/scrot -F ./-
scrot: Saving to file ./- failed: No such file or directory

Using -F - however works fine.

Originally posted at: https://github.com/resurrecting-open-source-projects/scrot/pull/229#issuecomment-1474518175

N-R-K commented 1 year ago

This seems to be due to the extension check. If filename is ./- then the following branch won't execute and imlib_image_set_format() won't get called.

https://github.com/resurrecting-open-source-projects/scrot/blob/c0f029e6150a743747dbdc7105d1cc4e98260b15/src/scrot.c#L145-L147

N-R-K commented 1 year ago

Looks like this will be more tricky than imagined. If someone uses a.com as the output filename, then we won't set any format and imlib2 will fail since it doesn't have any .com savers.

I was thinking it might be good idea to retry with PNG set if the error from imlib2 is due to not having a saver for that format. However, then in cases like file.webp the user most likely is going to expect a webp output. But if imlib2 doesn't have webp saver, and we end up silently saving it as PNG, then that's unexpected.

I don't think relying on extension to get the output file format was a good idea. We should probably just add a --format flag so users can more explicitly set the output format.

Disonantemus commented 1 year ago

Using: scrot --format webp resulting file was .png, expected was .webp, checking with medianinfo & ffmpeg says webp:

> mediainfo 2023-04-28-113049_1920x1080_scrot.png
General
Complete name                            : 2023-04-28-113049_1920x1080_scrot.png
Format                                   : WebP
File size                                : 88.2 KiB

Image
Format                                   : WebP
> ffprobe -hide_banner 2023-04-28-113049_1920x1080_scrot.png
Input #0, webp_pipe, from '2023-04-28-113049_1920x1080_scrot.png':
  Duration: N/A, bitrate: N/A
  Stream #0:0: Video: webp, yuv420p(tv, bt470bg/unknown/unknown), 1920x1080, 25 fps, 25 tbr, 25 tbn

It's safe to just rename to webp?