Using as thumbnailer
This can be easily done with:
/usr/share/thumbnailers/raw.thumbnailers
[Thumbnailer Entry]
TryExec=raviewer-thumbnailer
Exec=raviewer-thumbnailer %s %i %o
MimeType=image/x-adobe-dng;image/x-canon-cr2;image/x-canon-cr3;image/x-canon-crw;image/x-nikon-nef;image/x-nikon-nrw;image/x-olympus-orf;image/x-pentax-pef;image/x-sony-arw;image/x-sony-sr2;image/x-epson-erf;image/x-minolta-mrw;image/x-fuji-raf;image/x-panasonic-rw;image/x-panasonic-rw2;
/usr/bin/raviewer-thumbnailer
#!/bin/bash
SIZE="$1"
INPUT="$2"
OUTPUT="$3"
raviewer -f "$INPUT" -e "$OUTPUT" --endianness auto
There're only two problems:
- Parameter size should be ignored. Using
-wor--widthimage ends distorted. - On GUI there's an option "find resolutions" which offers 2 resolutions (for widths).
Using this diff we can inspect predicted widths and heights:
diff --git i/raviewer/__main__.py w/raviewer/__main__.py
index f7426a8..340c4f9 100644
--- i/raviewer/__main__.py
+++ w/raviewer/__main__.py
@@ -64,10 +64,17 @@ def run(file_path, width, height, color_format, export, args):
img = load_image(file_path)
if color_format == "unknown":
color_format, _ = classify_top1(img)
+ predict_widths = [item[0] for item in predict_resolution(img, color_format)]
if width == 0:
- width, _ = predict_resolution(img, color_format)[0]
+ width = predict_widths[0]
predictions, endianness = classify_all(img)
- img = parse_image(img.data_buffer, color_format, width, Endianness[endianness].value)
+ img = parse_image(img.data_buffer, color_format, predict_widths[0], Endianness[endianness].value)
+ predict_heights = []
+ predict_heights.append(img.height)
+ img = parse_image(img.data_buffer, color_format, predict_widths[1], Endianness[endianness].value)
+ predict_heights.append(img.height)
+ print(predict_widths[0], predict_heights[0])
+ print(predict_widths[1], predict_heights[1])
if height < 1: height = img.height
save_image_as_file(get_displayable(img, height), export)
From this file:
output is:
[480, 240]
[160, 320]
first guess looks incorrect:
Second one looks better:
- Is there any chance to know from original file what resolution is the correct one?
- Is possible to set a width or height honoring height/witdh proportions?
My only idea around this is detect if it creates a duplicate image (not sure how feasible that is) but guess the width and height for a raw file seems to be a common problem.
From source images on http://www.rinkydinkelectronics.com/library.php?id=53. Using raviewer as thumbnailer
UTFT_tinyFAT/Image-files
Some images choosing first guess incorrectly:
while other files just detect dimensions correctly:
It looks as though the problem you see is only visible for portrait images (i.e. correct height is larger than the correct width) and all horizontal images are detected properly. Is that assumption correct?
I don't think we have to detect whether the double images are the same (especially that they aren't, we just see odd lines on the left and even lines on the right). I think in case if the second predicted width is exactly two times smaller than the first one, we could make an assumption that the smaller one is always correct.
Alternatively (and this could be even better), we could try to give priority to dimensions with common aspect ratios. In the case of your input data 4:3 (or 3:4 for portrait mode - 240:320), would be much more common than the predicted 3:1 ratio (480x160).
Feel free to give it a go and experiment with some additional detection features
aspect ratio makes lot of sense, making a wrong guess on a unusual raw image format probably is not problematic
Will create some PR around that idea, and if is too specific we can wrap in a configurable parameter