GNU/Linux >> Linux の 問題 >  >> Ubuntu

テキストのサムネイルを生成しますか?

一部のテキストファイルのサムネイルを生成する必要があります。
明らかに、システムにはこれを正確に実行する機能があります(スクリーンショットを参照)。これらの画像にアクセスして、後で使用するためにコピーする方法はありますか?

または、このための特別なコマンド(ツール)はありますか?

私はこれを見ました:
コマンドラインのサムネイル

そしてこれ:
サムネイルを事前に生成するようにノーチラスに指示するにはどうすればよいですか?

これは便利でしたが、テキストを処理できるものはありませんでした。

承認された回答:

Imagemagickを使用してテキストアイコンを作成する

ここと同じ原理に基づいて、以下のスクリプトは、Imagemagickを使用してテキストファイルからテキストアイコンを作成します。

丸みを帯びた背景画像の色とテキストの色は、スクリプトの先頭(およびその他の多くのプロパティ)で設定できます。

機能
テキストファイルを読み取り、最初の4行を取得します(n_lines = 4で設定) )、最初の7文字(n_chars = 10で設定) )各行の、およびサイズの画像の上にオーバーレイを作成します。 psize = "100x100"

使用方法

スクリプトにはimagemagickが必要です インストールするもの:

sudo apt-get install imagemagick

次に:

  1. スクリプトを空のファイルにコピーします
  2. create_texticon.pyとして保存します
  3. ヘッドセクションで設定:

    • アイコンの背景の色
    • アイコンのテキストレイヤーの色
    • 作成されたアイコンのサイズ
    • アイコンに表示する行数
    • アイコンに表示する1行あたりの(最初の)文字数
    • 画像を保存するパス
  4. テキストファイルを引数として実行します:

    python3 /path/to/create_texticon.py </path/to/textfile.txt>
    

スクリプト

#!/usr/bin/env python3
import subprocess
import sys
import os
import math

temp_dir = os.environ["HOME"]+"/"+".temp_iconlayers"
if not os.path.exists(temp_dir):
    os.mkdir(temp_dir)

# --- 
bg_color = "#DCDCDC"                                # bg color
text_color = "black"                                # text color
psize = [64, 64]                                    # icon size
n_lines = 4                                         # number of lines to show
n_chars = 9                                         # number of (first) characters per line
output_file = "//eadn-wc01-5196795.nxedge.io/path/to/output/icon.png"            # output path here (path + file name)
#---

temp_bg = temp_dir+"/"+"bg.png"; temp_txlayer = temp_dir+"/"+"tx.png"
picsize = ("x").join([str(n) for n in psize]); txsize = ("x").join([str(n-8) for n in psize])

def create_bg():
    work_size = (",").join([str(n-1) for n in psize])
    r = str(round(psize[0]/10)); rounded = (",").join([r,r])
    command = "convert -size "+picsize+' xc:none -draw "fill '+bg_color+
              ' roundrectangle 0,0,'+work_size+","+rounded+'" '+temp_bg
    subprocess.call(["/bin/bash", "-c", command])

def read_text():
    with open(sys.argv[1]) as src:
        lines = [l.strip() for l in src.readlines()]
        return ("n").join([l[:n_chars] for l in lines[:n_lines]])

def create_txlayer():
    subprocess.call(["/bin/bash", "-c", "convert -background none -fill "+text_color+
                      " -border 4 -bordercolor none -size "+txsize+" caption:"+'"'+read_text()+'" '+temp_txlayer])

def combine_layers():
    create_txlayer(); create_bg()
    command = "convert "+temp_bg+" "+temp_txlayer+" -background None -layers merge "+output_file
    subprocess.call(["/bin/bash", "-c", command])

combine_layers

Ubuntu
  1. Virtualbox 5.1.2 for Ubuntu 14.04.5?

  2. なぜSublime-text2が私にとってもう始まらないのかを判断する方法は?

  3. Linux 用の Windows スタイルの端末ベースのテキスト エディター

  1. テキスト操作のための3つの必知のLinuxコマンド

  2. LinuxでAsciiDocを使用するための完全ガイド

  3. すべての証明書チェーンのHpkpフィンガープリントを生成しますか?

  1. 着信メールをText/plainからText/htmlに変更しますか?

  2. ディレクトリでファイルを検索し、結果をテキストファイルに出力しますか?

  3. Gvimのショートカット?