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.

4
  • What are you on about? Ubuntu has thumbnails for both png and jpeg : imgur.com/vUCRRCt
    – tatsu
    Apr 12, 2019 at 12:14
  • 1
    Possible duplicate of Refresh thumbnails in nautilus Apr 12, 2019 at 12:18
  • @mikewhatever This isn't really a duplicate, here a different question is asked.
    – v010dya
    Apr 12, 2019 at 14:54
  • True, it's not a duplicate of that question.
    – karel
    Apr 13, 2019 at 9:06

1 Answer 1

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).

5
  • Does process all the images (failing when no corresponding png is found as expected), and create thumbnails in the apropiate folders. But the icons still show as the Clip Studio Paint logo.
    – metichi
    Apr 12, 2019 at 17:37
  • @metichi Could it be that nautilus has changed its location for thumbnails? I don't use that file manager, can you double check that other thumbnails are being generated there?
    – v010dya
    Apr 12, 2019 at 17:59
  • There seems to be plenty of other thumbnails in that folder
    – metichi
    Apr 13, 2019 at 14:05
  • @metichi Ok, i'm not sure what it can be. Are you viewing the directory in icon mode?
    – v010dya
    Apr 15, 2019 at 9:24
  • Not 100% sure what icon mode is, but the .png files have their thumbnails alright. Anyway, that script does help a lot and is a great thing to help me understand what's going on and go look for other stuff. Thank you for all the help so far!
    – metichi
    Apr 15, 2019 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.