1

I draw a lot with Clip Studio Paint, wich works almost flawlessly with wine, but the only major caveat is that the original files are in a format that doesn't have thumbnail support in linux (as far as I can tell).

For most files I will have 2 versions. File.clip (the CSP format) and File.png. I would like to use .png (or its thumbnail) as a thumbnail for File.clip.

So, how would you add a thumbnail to a random file from the command line?

Im working in ubuntu 18.04 and nautilus.

Edit: Changed the description of what I want to do exactly to make it clearer.

v010dya
  • 1,502
metichi
  • 927

1 Answers1

1

Ok, so as i understand it, you are seeking to create a thumbnail of a file by using a different file (created predictably).

We can try something like this:

#!/bin/bash

# Based on CC-BY 2016 Marcin Kaminski https://askubuntu.com/users/98096/marcin-kaminski
# https://askubuntu.com/a/201894/216568

# USAGE: mkthumb.sh [-s] [-r] <path> [path]
# create nautilus thumbnails for clips in the directories (and their
# sub-directories) given as parameters.
# -s is used to skip generating thumbnails that already exist

skip_existing=0
if [[ "${1}" == "-s" ]]; then
    skip_existing=1
    shift
fi

maxdepth="1"
if [[ "${1}" == "-r" ]]; then
    maxdepth="9999"
    shift
fi

mkImageThumb() {
    size="${3}"
    file="${1}"
    dest="${2}"
    convert -thumbnail ${size}x${size} "${file}[0]" "${dest}" &>/dev/null
    if (( $? == 0 )); then
        echo "OK   ${file} [${dest}]"
    else
        echo "FAIL ${file}"
    fi
}

OLDIFS="${IFS}"
IFS=$'\n'
for dir in $@; do
    realdir=`realpath "${dir}"`
    echo "Processing directory ${realdir}"
    for file in $(find "${realdir}" -maxdepth ${maxdepth} -regextype posix-egrep -iregex '.*\.clip'); do
        md5=$(echo -n "${file}" | perl -MURI::file -MDigest::MD5=md5_hex -ne 'print md5_hex(URI::file->new($_));')
        image=$(dirname "${file}")/$(basename "${file}" .clip).png
        dest="${HOME}/.cache/thumbnails/normal/${md5}.png"
        if [[ ! -f "${dest}" || "${skip_existing}" != "0" ]]; then
            mkImageThumb "${image}" "${dest}" 128
        else
            echo "SKIP ${file}"
        fi
        dest="${HOME}/.cache/thumbnails/large/${md5}.png"
        if [[ ! -f "${dest}" || "${skip_existing}" != "0" ]]; then
                mkImageThumb "${image}" "${dest}" 256
        else
            echo "SKIP ${file}"
        fi
    done
done
IFS="${OLDIFS}"

This script will take the whole directory and generate the needed thumbnails (i haven't tested the script now, but it should).

v010dya
  • 1,502