Minimalist command-line image viewer

Paint programs, vector editors, 3d modelers, animation editors, etc.
Post Reply
Message
Author
User avatar
6502coder
Posts: 677
Joined: Mon 23 Mar 2009, 18:07
Location: Western United States

Minimalist command-line image viewer

#1 Post by 6502coder »

Here's a tiny command-line program to display an image on the screen. The man page pretty much says it all:

[NOTE: this is out of date. The zip file has the latest man page]

NAME
simv - simple image viewer

SYNOPSIS
simv [filename [x-coord y-coord]]

DESCRIPTION
simv is a minimalist Gtk image viewer. It displays images and that's all -- no zooming, no scrolling, no resizing, no editing.

simv will attempt to open the named image file, and if successful it will render the image on the screen. The image is rendered without window ornamentation of any kind. You may specify the placement of the image by passing the optional x- and y-coordinates. (Keep in mind that your window manager may choose not to honor your request.)

Clicking anywhere on the image will close simv.

If the filename is "-" or begins with "-", the usage syntax is printed to stderr.

When called with no arguments, simv opens as a barebones GUI application.

NOTES
simv was created to address a need to be able to throw a "windowless" image up on the screen from a shell script. The GUI mode is merely a legacy from the original source code from which simv was adapted.

simv was compiled on Puppy 4.1.2 Retro and should work on pretty much any Puppy.

Zip file with the executable and man page:
Attachments
simv3.zip
Third and final (?) version
(5.95 KiB) Downloaded 238 times
Last edited by 6502coder on Mon 22 Dec 2014, 04:07, edited 2 times in total.

sheldonisaac
Posts: 902
Joined: Mon 22 Jun 2009, 01:36
Location: Philadelphia, PA

Re: Minimalist command-line image viewer

#2 Post by sheldonisaac »

Much snipped.
6502coder wrote:Here's a tiny command-line program to display an image on the screen. The man page pretty much says it all:

simv [filename [x-coord y-coord]]
Clicking anywhere on the image will close simv.
Yep, works fine, thank you!

Code: Select all

simv /usr/share/pixmaps/FBReader.png 600 400
puts it in about the middle of the 14" screen on this Dell Latitude E6410, Lucid Puppy 5.2.8.7
Dell E6410: BusterPup, BionicPup64, Xenial, etc
Intel DQ35JOE, Dell Vostro 430
Dell Inspiron, Acer Aspire One, EeePC 1018P

anikin
Posts: 994
Joined: Thu 10 May 2012, 06:16

#3 Post by anikin »

Works fine on DebianDog, thank you!
Last edited by anikin on Tue 23 Dec 2014, 03:52, edited 1 time in total.

User avatar
Dingo
Posts: 1437
Joined: Tue 11 Dec 2007, 17:48
Location: somewhere at the end of rainbow...
Contact:

#4 Post by Dingo »

where download the source code?
replace .co.cc with .info to get access to stuff I posted in forum
dropbox 2GB free
OpenOffice for Puppy Linux

User avatar
6502coder
Posts: 677
Joined: Mon 23 Mar 2009, 18:07
Location: Western United States

#5 Post by 6502coder »

@sheldonisaac

My bad. New version (2) uploaded, this should respect the x-y coords correctly.

User avatar
6502coder
Posts: 677
Joined: Mon 23 Mar 2009, 18:07
Location: Western United States

#6 Post by 6502coder »

I have posted a 3rd (and final) version of simv, to address the following issue, which pertains only to the behavior of simv when you pass it a filename argument.

By default the image is rendered in a standard Gtk window, and therefore the window's placement is ultimately determined by the window manager. Even if you supply the optional x-y coords, these are only hints to the window manager. In practice, if the image is small enough to fit entirely on the screen at the specified position, the window manager will honor the request. But if the image is too large to fit entirely on the screen, then all bets are off, and it is up to the window manager to decide where to place the window.

On the other hand, window managers do not control the placement of Gtk "pop-up" windows. If you supply the x-y coords, these will be honored, even if the image will not fit entirely on the screen at the specified position. However, a pop-up window stays on top of all other windows. This may not be what you want.

So simv now has a "-p" option. This will cause the image to be rendered in a pop-up window instead of a regular window, with the pros and cons I have spelled out above.

Having exhausted my limited knowledge of Gtk, I should leave it to smarter folks to tinker with any further improvements! The source code is included in the zip file.

slavvo67
Posts: 1610
Joined: Sat 13 Oct 2012, 02:07
Location: The other Mr. 305

#7 Post by slavvo67 »

Do you know what / how many formats this handles?

Thanks,

Slavvo67

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#8 Post by MochiMoppel »

It can get even tinier. Here is a minimalistic-as-can-be script I wrote a while ago.
Make a desktop icon linking to the script and drag&drop images on it
To move: Alt+drag mouse with left mouse button pressed
To close: Alt+F4
The only drawback: The small border around the image (see screenshot), no borders with simv. If anyone knows how to get rid of the border I would be grateful for a hint.
EDIT SFR solved the problem (see next post).

Code: Select all

#!/bin/sh
gtkdialog -s <<< '
<window decorated="false">
<pixmap><input file>'"$1"'</input></pixmap>
</window>'
Attachments
miniviewers.png
(32.68 KiB) Downloaded 345 times
Last edited by MochiMoppel on Mon 22 Dec 2014, 11:58, edited 1 time in total.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#9 Post by SFR »

MochiMoppel wrote:If anyone knows how to get rid of the border I would be grateful for a hint.
I was just looking for the same thing myself and found it!
It's: <window margin="0" ... >
[src]

Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#10 Post by MochiMoppel »

SFR wrote:It's: <window margin="0" ... >
[src]!
Great! Thank you!
I also like the linked specification: "Default value: 0" :lol:

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#11 Post by amigo »

I wonder why you call it a command-line program, when it is obviously a graphical(X/GTK) program

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#12 Post by Geoffrey »

Slightly larger with more features.

Really needs to fit to screen if the image is larger than the screen res.

Passing it on to whomever wants to add to it.

Show image on a button, but it does have a border, click image to close, show icon preview and image name on taskbar.

Tested with these file types: png, jpg, bmp, gif, xpm, ppm, pgm, pbm, pnm, tga, pcx

Code: Select all

#!/bin/sh
EXT="${1##*.}"
if [ "$EXT" = "png" ] || [ "$EXT" = "jpg" ] || [ "$EXT" = "bmp" ] \
|| [ "$EXT" = "gif" ] || [ "$EXT" = "xpm" ] || [ "$EXT" = "ppm" ] || [ "$EXT" = "pgm" ] \
|| [ "$EXT" = "pbm" ] || [ "$EXT" = "pnm" ] || [ "$EXT" = "tga" ] || [ "$EXT" = "pcx" ]; then
gtkdialog -s <<< '
<window title="'${1##*/}'" margin="0" decorated="false" image-name="'$1'">
<button>
<input file>"'$1'"</input>
</button>
<action type="exit">exit</action>
</window>'
else
echo "Usage: [File] png, jpg, bmp, gif, xpm, ppm, pgm, pbm, pnm, tga, pcx"; exit 0
fi
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#13 Post by amigo »

A little cleaner:

Code: Select all

case $EXT in
  jpg|png|... ) actions ;;
esac

User avatar
6502coder
Posts: 677
Joined: Mon 23 Mar 2009, 18:07
Location: Western United States

#14 Post by 6502coder »

MochiMoppel wrote:It can get even tinier...
Nice! Good to know.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#15 Post by MochiMoppel »

Geoffrey wrote:Passing it on to whomever wants to add to it.
Hi, I'm whomever and I would love to subtract from it :wink:

I like the idea to sniff for image file type. If it's not an image file, my script would show an ugly default icon.
But checking extension is not reliable. Even with amigo's more elegant approach you can't catch all upper/lowercase variants, can't catch files with no extension at all and can't catch your brothers pr0n collection where nicepicXXX.jpg masquerades as nicepicXXX.txt. Therefore sniffing for the MIME type appears to me as a better approach.

What does image-name="'$1'" do?
<action> not needed here if you want the button to close the window

My stripped variant would look like this:

Code: Select all

#!/bin/sh
if [ "`file -ib "$1" | grep '^image'`" ]; then 
 gtkdialog -s <<< ' 
 <window title="'${1##*/}'" margin="0" decorated="false"> 
 <button> <input file>"'$1'"</input> </button>
 </window>' 
fi

slavvo67
Posts: 1610
Joined: Sat 13 Oct 2012, 02:07
Location: The other Mr. 305

#16 Post by slavvo67 »

I've sniffed the mime type and converted to the proper extension. It takes longer, though.

User avatar
Geoffrey
Posts: 2355
Joined: Sun 30 May 2010, 08:42
Location: Queensland

#17 Post by Geoffrey »

MochiMoppel wrote:What does image-name="'$1'" do?
Shows the image as a icon on the taskbar, though it does throw a warning in terminal.

Code: Select all

(gtkdialog:30447): Gdk-WARNING **: gdk_window_set_icon_list: icons too large
Could skip the taskbar.

Code: Select all

<window  skip-taskbar-hint="true"  margin="0" decorated="false">
<action> not needed here if you want the button to close the window
Yeah my bad.

Code: Select all

[ "`file -ib "$1" | grep '^image'`" ]
That doesn't seem to work for all images,
pcx are "application/octet-stream; charset=binary"
xpm "text/x-c; charset=us-ascii"

Code: Select all

[ "`file -ib "$1" | grep '^image\|octet-stream\|x-c;'`" ]
[b]Carolina:[/b] [url=http://smokey01.com/carolina/pages/recent-repo.html]Recent Repository Additions[/url]
[img]https://dl.dropboxusercontent.com/s/ahfade8q4def1lq/signbot.gif[/img]

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#18 Post by MochiMoppel »

Geoffrey wrote:
MochiMoppel wrote:What does image-name="'$1'" do?
Shows the image as a icon on the taskbar, though it does throw a warning in terminal
Doesn't work for me :cry:
That doesn't seem to work for all images,
pcx are "application/octet-stream; charset=binary"
xpm "text/x-c; charset=us-ascii"
Haven't seen a pcx for years and my browser doesn't support them. Downloaded a sample and it worked with the script. Mime type is image/x-pcx.
It may not work for all image files, but let's be realistic: The script is a primitive personal tool. I don't expect it to cover much more than PNG,JPG,GIF...the ordinary stuff, and this it does well.

Post Reply