Skip to content

Commit

Permalink
Merge pull request #4 from iambumblehead/add-pdf-thumbnail
Browse files Browse the repository at this point in the history
Add pdf thumbnail
  • Loading branch information
iambumblehead authored Mar 3, 2024
2 parents c8eeada + 5c1be25 commit cb7c11c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# changelog

* 0.0.3 _Mar.03.2024_
* added pdf thumb generation [#4](https://github.com/iambumblehead/render-thumb-for.sh/pull/4)
* 0.0.2 _Mar.02.2024_
* added video thumb generation [#2](https://github.com/iambumblehead/render-thumb-for.sh/pull/2)
* added audio thumb generation [#3](https://github.com/iambumblehead/render-thumb-for.sh/pull/3)
Expand Down
27 changes: 26 additions & 1 deletion render-thumb-for.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,21 @@ mime_video_re="video/"
mime_svg_re="image/svg"
mime_img_re="image/"
mime_audio_re="audio/"
mime_pdf_re="application/pdf"

#default_wh="640 480"

img_dir="$HOME/.config/render-thumb-for"
if [ -n "${XDG_CONFIG_HOME}" ]; then
img_dir="$XDG_CONFIG_HOME/render-thumb-for"
fi

wh_max_get () {
IFS=" " read -r -a wh <<< "$1"

echo "$((${wh[0]} > ${wh[1]} ? ${wh[0]} : ${wh[1]}))"
}

wh_scaled_get () {
IFS=" " read -r -a wh_bgn <<< "$1"
IFS=" " read -r -a wh_max <<< "$2"
Expand Down Expand Up @@ -159,6 +168,19 @@ show_audio () {
img_sixel_paint "audioshot.png" "$aud_wh_scaled"
}

show_pdf () {
pdf_path=$1
pdf_wh_max=$2

pdftoppm \
-singlefile \
-f 1 -l 1 \
-scale-to "$(wh_max_get "$2")" \
-jpeg "$pdf_path" "pdfhot"

img_sixel_paint "pdfhot.jpg" "$pdf_wh_max"
}

start () {
img_path=$1
max_wh="$2 $3"
Expand All @@ -177,12 +199,15 @@ start () {
show_video "$img_path" "$max_wh"
elif [[ $img_mimetype =~ ^$mime_audio_re ]]; then
show_audio "$img_path" "$max_wh"
elif [[ $img_mimetype =~ ^$mime_pdf_re ]]; then
show_pdf "$img_path" "$max_wh"
fi
}

#start "/home/bumble/software/Guix_logo.png" 800 400
#start "/home/bumble/software/Guix_logo.svg" 800 800
#start "/home/bumble/ビデオ/#338 - The Commissioning of Truth [stream_19213].mp4" 800 400
start "/home/bumble/音楽/language/日本語 - Assimil/Assimil 10 テレビ.flac" 800 400
#start "/home/bumble/音楽/language/日本語 - Assimil/Assimil 10 テレビ.flac" 800 400
start "/home/bumble/ドキュメント/8020japanese/80-20_Japanese_(Kana___Kanji_Edition).pdf" 800 400
echo "$is_cmd_ffmpeg"
# ffmpeg -i "/home/bumble/ビデオ/#338 - The Commissioning of Truth [stream_19213].mp4" -vframes 1 -f rawvideo -y /dev/null 2>&1

0 comments on commit cb7c11c

Please sign in to comment.