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
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
Labelme is a graphical image annotation tool, It is written in Python and uses Qt for its graphical interface

Image Polygonal Annotation with Python (polygon, rectangle, circle, line, point and image-level flag annotation).

Kentaro Wada 9.6k Jan 09, 2023
Image comparison slider component for Streamlit

Streamlit Image Comparison Component A simple Streamlit Component to compare images with a slider in Streamlit apps using Knightlab's JuxtaposeJS. It

fatih 109 Dec 23, 2022
Transfers a image file(.png) to an Excel file(.xlsx)

Transfers a image file(.png) to an Excel file(.xlsx)

Junu Kwon 7 Feb 11, 2022
display: a browser-based graphics server

display: a browser-based graphics server Installation Quick Start Usage Development A very lightweight display server for Torch. Best used as a remote

Szymon Jakubczak 205 Oct 17, 2022
Remove Background from Image With Python

Install Library pypi $ pip3 install xremovebg

krypton 4 May 26, 2022
Python library for ascii graphics

Python library for ascii graphics

Anton 6 Oct 20, 2021
Using P5.js, Processing and Python to create generative art

Experiments in Generative Art Using Python, Processing, and P5.js Quick Links Daily Sketches March 2021. | Gallery | Repo | Done using P5.js Genuary 2

Ram Narasimhan 33 Jul 06, 2022
A drop-in replacement for django's ImageField that provides a flexible, intuitive and easily-extensible interface for quickly creating new images from the one assigned to the field.

django-versatileimagefield A drop-in replacement for django's ImageField that provides a flexible, intuitive and easily-extensible interface for creat

Jonathan Ellenberger 490 Dec 13, 2022
MaryJane is a simple MJPEG server written in Python.

MaryJane is a simple MJPEG server written in Python.

bootrino 152 Dec 13, 2022
Python script to generate vector graphics of an oriented lattice unit cell

unitcell Python script to generate vector graphics of an oriented lattice unit cell Examples unitcell --type hexagonal --eulers 12 23 34 --axes --crys

Philip Eisenlohr 2 Dec 10, 2021
将位图转为彩色矢量 svg 图片

一个将位图描摹为彩色矢量 svg 图片的程序,是一个命令行工具,使用 Python 脚本实现,运行环境 Python3.8+。 ✨ 效果 以一个字帖图片为例,这是 png 格式的位图(370KB): 这是颜

Haujet Zhao 104 Dec 30, 2022
Goddard Image Analysis and Navigation Tool

Copyright 2021 United States Government as represented by the Administrator of the National Aeronautics and Space Administration. No copyright is clai

NASA 12 Dec 23, 2022
Generate meme GIFs in which an image you choose can be viewed by the user only after they wait a whole hour.

Generate meme GIFs in which an image you choose can be viewed by the user only after they wait a whole hour.

Feliks Maak 1 Jan 31, 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
hashmask reverse lookup

ImageHashMasks Lookup Hashmask NFT index from a picture Setup pip install pillow click imagehash Usage $ python imagehashmasks.py

17 Nov 29, 2021
Find target hash collisions for Apple's NeuralHash perceptual hash function.💣

neural-hash-collider Find target hash collisions for Apple's NeuralHash perceptual hash function. For example, starting from a picture of this cat, we

Anish Athalye 630 Jan 01, 2023
Napari 3D Ortho Viewer - an ortho viewer for napari for 3D images

napari-3d-ortho-viewer Napari 3D Ortho Viewer - an ortho viewer for napari for 3D images This napari plugin was generated with Cookiecutter using @nap

niklas netter 5 Nov 28, 2022
Digital image process Basic algorithm

These are some basic algorithms that I have implemented by my hands in the process of learning digital image processing, such as mean and median filtering, sharpening algorithms, interpolation scalin

JingYu 2 Nov 03, 2022
QR Code Generator

In this project, we'll be using some libraries to instantly generate authentic QR Codes and export them in various formats

Hassan Shahzad 3 Jun 02, 2022