A Gtk based Image Selector with Preview

Overview

gtk-image-selector

window-with-preview.png

This is an attempt to restore Gtk Image Chooser "lost functionality": displaying an image preview when selecting images...

This is a simple python script; its only dependency is the gobject module.

When an image file is selected, its filename will be printed on stdout.

How it all works

The script will read its parameters from 3 sources:

  1. Hardcoded values
  2. Configuration file(s)
  3. Command line parameters

in this order.

It will display an image preview (either of the selected image or the default "no preview" image), and will exit when the "Select" button is clicked (or when "Enter" is pressed).

Parameters

The following are the command line parameters:

$ gtk-image-selector -h
usage: gtk-image-selector [-h] [-n] [-m DEFAULT_IMAGE] [-f FILE]
                          [-d DIRECTORY] [-p POSITION] [-r PREVIEW_SIZE] [-s]
                          [-i ICON] [-w WINDOW_TITLE] [-o OK_LABEL]
                          [-c CANCEL_LABEL] [-t FILTER_LABEL] [-l SIZE_LABEL]
                          [--dump-config]

A Gtk Image Chooser with Preview

optional arguments:
  -h, --help            show this help message and exit
  -n, --no-config       do not attempt to read any config file; just use the
                        command line parameters
  -m DEFAULT_IMAGE, --default-image DEFAULT_IMAGE
                        the image to display when no preview is available
                        (proposed size: 512x521)
  -f FILE, --file FILE  default file to select
  -d DIRECTORY, --directory DIRECTORY
                        default directory to show
  -p POSITION, --position POSITION
                        set window position, either as X,Y of "center"
  -r PREVIEW_SIZE, --preview-size PREVIEW_SIZE
                        set preview image size (100-1000)
  -s, --show-scale      show scale widget (hidden by default)
  -i ICON, --icon ICON  set window icon
  -w WINDOW_TITLE, --window_title WINDOW_TITLE
                        set window title
  -o OK_LABEL, --ok-label OK_LABEL
                        set OK button label
  -c CANCEL_LABEL, --cancel-label CANCEL_LABEL
                        set Cancel button label
  -t FILTER_LABEL, --filter-label FILTER_LABEL
                        set filter field label
  -l SIZE_LABEL, --size-label SIZE_LABEL
                        set size field label
  --dump-config         print a sample config file (can be saved to /etc/gtk-
                        image-selector.conf or ~/.config/gtk-image-
                        selector/config)

The default image

When no image is selected, or the selected image is broken, gtk-image-selector will display its default image instead.

This image can be any valid image one can think of, but having a size of 512x512 or 256x265 (depending on preview size used).

gtk-image-selector will by default use "image-x-generic.png" of the "Adwaita" theme; when this is not found (and no other image is specified) the following message will appear and the script will terminate.

no-default-image.png

To use a different image, one would use the -m (--default-image) command line parameter. For example, using the "no-preview.png" file provided in this repo

./gtk-image-selector -m no-preview.png

would give this result.

window-no-preview.png

Finally, the image can be specified in the configuratio file, parameter "default_image".

Using a configuration file

gtk-image-selector can read two configuration files

  1. /etc/gtk-image-selector.conf (system wide settings)
  2. ~/.config/gtk-image-selector (user settings)

To see the default settings, just execute the command:

$ gtk-image-selector --dump-config

which prints:

# the default folder to browse
folder =

# the default size of the image preview
preview_size = 256

# the image to show when no image file is selected
# or when the selected image is broken
# please make sure this image actually exists
default_image = /usr/share/icons/Adwaita/512x512/mimetypes/image-x-generic.png

# the icon to use as a window icon
icon = /usr/share/icons/Adwaita/16x16/mimetypes/image-x-generic.png

# set this to True to display the image scaling widget
show_scale = False

# window title and labels
window_title = Select an Image
ok_label = _Select
cancel_label = _Cancel
filter_label = Images
size_label = Size:

As you can see there are three types of settings:

  • working settings (folder, preview_size, show_scale)
  • icon and image settings (default_image, icon)
  • localization settings (window_title, ok_label, etc.)

Combining these settings in the system wide config file and user config file and command line parameters, one can achieve various results.

Using the scale widget

The application can display a scale widget, which will help you set the preview image size on the fly.

The scale widget is enabled using

  • the -s (--show-scale) command line parameter, or
  • the "show_scale" configuration option

In this case, the window will be as shown in the image below.

window-with-scale.png

Please keep in mind that, changing the preview size will probably also change the window size, which is something that one has to get used to.

You might also like...
Fast Image Retrieval is an open source image retrieval framework

Fast Image Retrieval is an open source image retrieval framework release by Center of Image and Signal Processing Lab (CISiP Lab), Universiti Malaya. This framework implements most of the major binary hashing methods, together with both popular backbone networks and public datasets.

Fast Image Retrieval (FIRe) is an open source image retrieval project

Fast Image Retrieval (FIRe) is an open source image retrieval project release by Center of Image and Signal Processing Lab (CISiP Lab), Universiti Malaya. This project implements most of the major binary hashing methods to date, together with different popular backbone networks and public datasets.

A Python Script to convert Normal PNG Image to Apple iDOT PNG Image.

idot-png-encoder A Python Script to convert Normal PNG Image to Apple iDOT PNG Image (Multi-threaded Decoding PNG). Usage idotpngencoder.py -i inputf

Anaglyph 3D Converter - A python script that adds a 3D anaglyph style effect to an image using the Pillow image processing package.
Anaglyph 3D Converter - A python script that adds a 3D anaglyph style effect to an image using the Pillow image processing package.

Anaglyph 3D Converter - A python script that adds a 3D anaglyph style effect to an image using the Pillow image processing package.

Pyconvert is a python script that you can use to convert image files to another image format! (eg. PNG to ICO)
Pyconvert is a python script that you can use to convert image files to another image format! (eg. PNG to ICO)

Pyconvert is a python script that you can use to convert image files to another image format! (eg. PNG to ICO)

Simple Python package to convert an image into a quantized image using a customizable palette
Simple Python package to convert an image into a quantized image using a customizable palette

Simple Python package to convert an image into a quantized image using a customizable palette. Resulting image can be displayed by ePaper displays such as Waveshare displays.

An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C.
An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C.

vizh An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C. Overview Her

impy is an all-in-one image analysis library, equipped with parallel processing, GPU support, GUI based tools and so on.
impy is an all-in-one image analysis library, equipped with parallel processing, GPU support, GUI based tools and so on.

impy is All You Need in Image Analysis impy is an all-in-one image analysis library, equipped with parallel processing, GPU support, GUI based tools a

Next-generation of the non-destructive, node-based 2D image graphics editor
Next-generation of the non-destructive, node-based 2D image graphics editor

Non-destructive, node-based 2D image graphics editor written in Python, focused on simplicity, speed, elegance, and usability

Owner
Spiros Georgaras
Spiros Georgaras
Nanosensor Image Processor (NanoImgPro), a python-based image analysis tool for dopamine nanosensors

NanoImgPro Nanosensor Image Processor (NanoImgPro), a python-based image analysis tool for dopamine nanosensors NanoImgPro.py contains the main class

null 1 Mar 2, 2022
Image-Viewer is a Windows image viewer based on Python 3.

Image-Viewer Hi! Image-Viewer is a Windows image viewer based on Python 3. Using You must download Image-Viewer.exe from the root of the repository. T

null 2 Apr 18, 2022
Seaborn-image is a Python image visualization library based on matplotlib and provides a high-level API to draw attractive and informative images quickly and effectively.

seaborn-image: image data visualization Description Seaborn-image is a Python image visualization library based on matplotlib and provides a high-leve

null 48 Jan 5, 2023
An open source image editor which can manipulate an image in many ways!

Image Editor - An open source image editor which can manipulate an image in many ways! If you need any more modes in repo or I

TroJanzHEX 44 Nov 17, 2022
Image enhancing model for making a blurred image to be somehow clearer than before

This is a very small prject which helps in enhancing the images by taking a Input images. This project has many features like detcting the faces and enhaning the faces itself and also a feature which enhances the whole image

null 3 Dec 3, 2021
Easily turn large sets of image urls to an image dataset. Can download, resize and package 100M urls in 20h on one machine.

img2dataset Easily turn large sets of image urls to an image dataset. Can download, resize and package 100M urls in 20h on one machine. Also supports

Romain Beaumont 1.4k Jan 1, 2023
A pure python implementation of the GIMP XCF image format. Use this to interact with GIMP image formats

Pure Python implementation of the GIMP image formats (.xcf projects as well as brushes, patterns, etc)

FHPyhtonUtils 8 Dec 30, 2022
Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in Python

AICSImageIO Image Reading, Metadata Conversion, and Image Writing for Microscopy Images in Pure Python Features Supports reading metadata and imaging

Allen Institute for Cell Science - Modeling 137 Dec 14, 2022
This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specialized data structure called VP-Tree which makes searching an image on a dataset of 100Ks almost instantanious

Offline Reverse Image Search Overview This app finds duplicate to near duplicate images by generating a hash value for each image stored with a specia

null 53 Nov 15, 2022
Quickly 'anonymize' all people in an image. This script will put a black bar over all eye-pairs in an image

Face-Detacher Quickly 'anonymize' all people in an image. This script will put a black bar over all eye-pairs in an image This is a small python scrip

Don Cato 1 Oct 29, 2021