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.

Owner
Spiros Georgaras
Spiros Georgaras
Leshycam - Generate Inscryption styled portrait sprites from any image

Leshy's Camera Generate Inscryption styled portrait sprites from any image. Setu

3 Sep 27, 2022
An agnostic Canvas API for the browser-less and insane

Apollo An agnostic Canvas API for the browser-less and mildly insane. Project Apollo is a Pythonic re-imagining of HTML Canvas element implementati

1 Jan 13, 2022
Magic-Square - Creates a magic square by randomly generating a list until the list happens to be a magic square

Magic-Square Creates a magic square by randomly generating a list until the list happens to be a magic square. Done as simply as possible... Frequentl

Nick 2 Jan 01, 2022
Create a random fluent image based on multiple colors.

FluentGenerator Create a random fluent image based on multiple colors. Navigation Example Install Update Usage In Python console FluentGenerator Fluen

1 Feb 02, 2022
Optimize/Compress images using python

Image Optimization Using Python steps to run the script run the command to install the required libraries pip install -r requirements.txt create a dir

Shekhar Gupta 1 Oct 15, 2021
Paper backup of files using QR codes

Generate paper backups for Linux. Currently command-linux Linux only. Takes any file, and outputs a "paper backup": a printable black-and-white pdf fu

Zachary Vance 27 Dec 28, 2022
PyLibTiff - a wrapper to the libtiff library to Python using ctypes

PyLibTiff is a package that provides: a wrapper to the libtiff library to Python using ctypes. a pure Python module for reading and writing TIFF and L

Pearu Peterson 105 Dec 21, 2022
A simple image to text converter with GUI!

TEXTEMAGE! Textemage is a quick tool that extracts text from images, it is a Python based GUI program(also available in executable version). This is a

Akascape 5 Oct 26, 2022
SimpleITK is an image analysis toolkit with a large number of components supporting general filtering operations, image segmentation and registration

SimpleITK is an image analysis toolkit with a large number of components supporting general filtering operations, image segmentation and registration

672 Jan 05, 2023
clesperanto is a graphical user interface for GPU-accelerated image processing.

clesperanto is a graphical user interface for a multi-platform multi-language framework for GPU-accelerated image processing. It is based on napari and the pyclesperanto-prototype.

1 Jan 02, 2022
Music Thumbnail Maker

Music Thumbnail Installing pip install TMFrame

krypton 4 Jan 28, 2022
The ctypes-based simple ImageMagick binding for Python

Wand Wand is a ctypes-based simple ImageMagick binding for Python, supporting 2.7, 3.3+, and PyPy. All functionalities of MagickWand API are implement

Eric McConville 1.2k Dec 30, 2022
🛹 Turn an SVG into an STL for stencil creation purposes

svg2stl This repository provides a script which takes as input an SVG such as this one: It outputs an STL file like this one: You can also see an inte

Max Halford 3 Dec 29, 2021
Pnuemonia Normal detection by using XRay images.

Pnuemonia Normal detection by using XRay images. Got image datas from kaggle(link is given in sources.txt file) also normal xray images from other site (also link is given) in order to avoid data dis

Zarina 1 Feb 28, 2022
A small Python module for BMP image processing.

micropython-microbmp A small Python module for BMP image processing. It supports BMP image of 1/2/4/8/24-bit colour depth. Loading supports compressio

Quan Lin 4 Nov 02, 2022
ImageStrike是一款用于CTF中图片隐写的综合利用工具

🎈 简介 ImageStrike是一款使用PyQT5开发,用于CTF中图片隐写的综合利用工具

zR00t1 133 Dec 27, 2022
PyPixelArt - A keyboard-centered pixel editor

PyPixelArt - A keyboard-centered pixel editor The idea behind PyPixelArt is uniting: a cmdpxl inspired pixel image editor applied to pixel art. vim 's

Douglas 18 Nov 14, 2022
Multiparametric Image Analysis

Documentation The documentation is available on populse_mia's website here Installation From PyPI, for users By cloning the package, for developers Fr

Populse 9 Dec 14, 2022
Random collage/montage generator with drop-shadow

Random Collage Example Usage These are the sample input files in $PWD for the below examples: 1.png 2.png 3.png 4.png 5.png 6.png 7.png 8.png 9.png 10

M B 1 Dec 07, 2021
Hello, this project is an example of how to generate a QR Code using python 😁

Hello, this project is an example of how to generate a QR Code using python 😁

Davi Antonaji 2 Oct 12, 2021