image: Add support for transparency when using pdf or svg as input

This commit is contained in:
dylan araps 2017-07-28 22:14:26 +10:00
parent 6cc08b5477
commit 41e4819658
2 changed files with 13 additions and 1 deletions

View File

@ -24,6 +24,8 @@
## Images ## Images
- [w3m] Fixed w3m-img not found on NixOS. - [w3m] Fixed w3m-img not found on NixOS.
- Added support for using all image types as input.
- Neofetch now supports `svg`, `tiff` etc.
## ASCII ## ASCII

View File

@ -2497,7 +2497,14 @@ get_image_size() {
make_thumbnail() { make_thumbnail() {
# Name the thumbnail using variables so we can # Name the thumbnail using variables so we can
# use it later. # use it later.
image_name="$crop_mode-$crop_offset-$width-$height-${image//\//_}.jpg" image_name="$crop_mode-$crop_offset-$width-$height-${image//'/'/_}"
# Handle file extensions.
case "${image##*.}" in
"eps"|"pdf"|"svg"|"gif"|"png")
image_name+=".png" ;;
*) image_name+=".jpg" ;;
esac
# Create the thumbnail dir if it doesn't exist. # Create the thumbnail dir if it doesn't exist.
mkdir -p "$thumbnail_dir" mkdir -p "$thumbnail_dir"
@ -2523,6 +2530,7 @@ make_thumbnail() {
-format "%[pixel:p{0,0}]" info:)" -format "%[pixel:p{0,0}]" info:)"
convert \ convert \
-background none \
"$image" \ "$image" \
-trim +repage \ -trim +repage \
-gravity south \ -gravity south \
@ -2534,6 +2542,7 @@ make_thumbnail() {
"fill") "fill")
convert \ convert \
-background none \
"$image" \ "$image" \
-trim +repage \ -trim +repage \
-scale "$width"x"$height"^ \ -scale "$width"x"$height"^ \
@ -2544,6 +2553,7 @@ make_thumbnail() {
"none") cp "$image" "$thumbnail_dir/$image_name" ;; "none") cp "$image" "$thumbnail_dir/$image_name" ;;
*) *)
convert \ convert \
-background none \
"$image" \ "$image" \
-gravity "$crop_offset" \ -gravity "$crop_offset" \
-crop "$size"x"$size"+0+0 \ -crop "$size"x"$size"+0+0 \