Skip to content
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

How to use the new image preview function #82

Closed
svenn71 opened this issue Mar 17, 2015 · 9 comments
Closed

How to use the new image preview function #82

svenn71 opened this issue Mar 17, 2015 · 9 comments

Comments

@svenn71
Copy link

svenn71 commented Mar 17, 2015

Hi,
I have discovered the new w3m image preview functionality. I have copied the bash script from the site referenced and made it reachable from vifm.
Problem is that the image overlays my left browsing pane while the right one is the preview pane.
I have tried to guess how things work, but I would be very very happy if I could get some help on putting the image properly into the preview pane at the right.
I can see my pictures, but in the wrong place.....

@xaizek xaizek self-assigned this Mar 17, 2015
@xaizek
Copy link
Member

xaizek commented Mar 17, 2015

Hi,

it won't work out of the box, that script was mentioned more for reference and needs some changes.

Modified version of the script (it lacks arguments checks, though):

#!/bin/bash
#
# z3bra -- 2014-01-21

W3MIMGDISPLAY="/usr/libexec/w3m/w3mimgdisplay"
FONTH=15 # Size of one terminal row
FONTW=8  # Size of one terminal column

X=$1
Y=$2
COLUMNS=$3
LINES=$4
FILENAME=$5

read width height <<< `echo -e "5;$FILENAME" | $W3MIMGDISPLAY`

x=$(($FONTW * $X))
y=$(($FONTH * $Y))

max_width=$(($FONTW * $COLUMNS))
max_height=$(($FONTH * $(($LINES - 2)))) # substract one line for prompt

if test $width -gt $max_width; then
    height=$(($height * $max_width / $width))
    width=$max_width
fi
if test $height -gt $max_height; then
    width=$(($width * $max_height / $height))
    height=$max_height
fi

w3m_command="0;1;$x;$y;$width;$height;;;;;$FILENAME\n4;\n3;"

echo -e $w3m_command|$W3MIMGDISPLAY

Note that you need to specify font width and height in pixels in the script. Full path to w3mimgdisplay might also differ.

Sample command for vifmrc (here script is called imgt and is somewhere in the $PATH):

fileviewer *.bmp,*.jpg,*.jpeg,*.png,*.gif,*.xpm
         \ imgt %px %py %pw %ph %c

If you use terminal multiplexer offset of current window should be added to coordinates in the script. Also it won't work in all terminals, but works fine at least in xterm.

@fogine
Copy link

fogine commented May 31, 2015

Hello,

I installed w3m and w3m-img.
But it seams that w3mimgdisplay returns empty result.
I tried above script but I get error "test: -gt: unary operator expected " on line 23 and 27.
After debug I've found that $width and $height vars in if statements are empty.

Here is how trace of the script looks like:

W3MIMGDISPLAY="/usr/lib/w3m/w3mimgdisplay"                                                             
#7: W3MIMGDISPLAY=/usr/lib/w3m/w3mimgdisplay                                                            
FONTH=15 # Size of one terminal row                                                                    
#8: FONTH=15                                                                                            
FONTW=8  # Size of one terminal column                                                                 
#9: FONTW=8                                                                                             

X=$1                                                                                                   
#11: X=115                                                                                              
Y=$2                                                                                                   
#12: Y=2                                                                                                
COLUMNS=$3                                                                                             
#13: COLUMNS=109                                                                                        
LINES=$4                                                                                               
#14: LINES=50                                                                                           
FILENAME=$5                                                                                            
#15: FILENAME=Folder.jpg                                                                                

read width height <<< `echo -e "5;$FILENAME" | $W3MIMGDISPLAY`                                         
#17: read width height                                                                                  
echo -e "5;$FILENAME" | $W3MIMGDISPLAY                                                                 
#117: echo -e '5;Folder.jpg'                                                                            
#117: /usr/lib/w3m/w3mimgdisplay                                                                        

x=$(($FONTW * $X))                                                                                     
#19: x=920                                                                                              
y=$(($FONTH * $Y))                                                                                     
#20: y=30                                                                                               

max_width=$(($FONTW * $COLUMNS))                                                                       
#22: max_width=872                                                                                      
max_height=$(($FONTH * $(($LINES - 2)))) # substract one line for prompt                               
#23: max_height=720                                                                                     

if test $width -gt $max_width; then                                                                    
    height=$(($height * $max_width / $width))                                                          
    width=$max_width                                                                                   
fi                                                                                                     
#25: test -gt 872                                                                                       
#/usr/local/bin/imgt: line 25: test: -gt: unary operator expected                                       
if test $height -gt $max_height; then                                                                  
    width=$(($width * $max_height / $height))                                                          
    height=$max_height                                                                                 
fi                                                                                                     
#29: test -gt 720                                                                                       
#/usr/local/bin/imgt: line 29: test: -gt: unary operator expected                                       

w3m_command="0;1;$x;$y;$width;$height;;;;;$FILENAME\n4;\n3;"                                           
#34: w3m_command='0;1;920;30;;;;;;;Folder.jpg\n4;\n3;'                                                                                                                             

Could I ask for your help? any hints?
Regards,

@xaizek
Copy link
Member

xaizek commented May 31, 2015

Hi @fogine,

are you sure the path to w3mimgdisplay (/usr/lib/w3m/w3mimgdisplay) is correct? On my system it's at /usr/libexec/w3m/w3mimgdisplay.

You could try running failing command just in a terminal, e.g.

$ echo '5;Folder.jpg' | /usr/libexec/w3m/w3mimgdisplay
506 662

It should print image size if file exists in current directory.

@fogine
Copy link

fogine commented May 31, 2015

Thanks @xaizek for quik reply,

But usr/libexec directory does not exists in my filesystem.
I'm sure that the binary file w3mimgdisplay exists under usr/lib/w3m/w3mimgdisplay.

if I run
$ echo '5;Folder.jpg' | /usr/libexec/w3m/w3mimgdisplay
I get

/bin/bash: /usr/libexec/w3m/w3mimgdisplay: No such file or directory
Press return ...

and if I run:
$ echo '5;Folder.jpg' | /usr/lib/w3m/w3mimgdisplay
I get:

Press return ...

Which results to empty output....

@xaizek
Copy link
Member

xaizek commented May 31, 2015

Maybe try other formats like PNG in case w3m is missing some dependencies. Also, do you see images in w3m (e.g. if you do w3m vifm.info there should be images)? It's unclear whether something with w3m or how script calls it.

@fogine
Copy link

fogine commented May 31, 2015

I tried several images in different format as well. I got same empty result.
if I do w3m vifm.info I get only text without images, but there is empty space in place where image should be...

Xubuntu 14.04 x64,
w3m version w3m/0.5.3+debian-15, options lang=en,m17n,image,color,ansi-color,mouse,gpm,menu,cookie,ssl,ssl-verify,external-uri-loader,w3mmailer,nntp,gopher,ipv6,alarm,mark,migemo

@fogine
Copy link

fogine commented May 31, 2015

However I've found this. Is anything that's mentioned there true for you @xaizek ?

Do you use terminal with 256color support enabled?
Which terminal do you use? (xterm?)

@xaizek
Copy link
Member

xaizek commented May 31, 2015

However I've found this. Is anything that's mentioned there true for you?

Works fine in native console. W3M_TTY isn't set anywhere.

Do you use terminal with 256color support enabled?
Which terminal do you use? (xterm?)

Yes, xterm (xterm-256color). But images are drawn not using terminal settings, they are just drawn at the same window more like its background. w3m won't display images well in terminals that use double buffering and thus flush background (xterm can be configured this way as well, but on most systems this behaviour is disabled), still I would expect image properties to work as usual.

$ w3m --version w3m version w3m/0.5.3, options lang=en,m17n,image,color,ansi-color,mouse,gpm,menu,cookie,ssl,ssl-verify,external-uri-loader,w3mmailer,nntp,gopher,ipv6,alarm,mark

@xaizek
Copy link
Member

xaizek commented Jul 20, 2015

At least original question is answered, other issues should be treated separately.

Finally moved this information to wiki page.

@xaizek xaizek closed this as completed Jul 20, 2015
@xaizek xaizek added the support label Jul 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants