Package Details: shitpost 4-1

Git Clone URL: https://aur.archlinux.org/shitpost.git (read-only, click to copy)
Package Base: shitpost
Description: A tool to create memes using CLI
Upstream URL: https://redd.it/5ezk1f
Licenses: custom:DWTFYW
Submitter: Baudouin
Maintainer: magnus-tesshu
Last Packager: magnus-tesshu
Votes: 10
Popularity: 0.000143
First Submitted: 2016-11-27 20:07 (UTC)
Last Updated: 2022-12-15 22:15 (UTC)

Latest Comments

magnus-tesshu commented on 2021-09-28 21:16 (UTC) (edited on 2021-09-28 21:16 (UTC) by magnus-tesshu)

@coolreader18 all the features in the patch are now in the base package, thanks!

coolreader18 commented on 2021-03-01 20:45 (UTC) (edited on 2021-03-01 20:45 (UTC) by coolreader18)

I've patched this a little bit with some qol improvements, figured someone might find it useful.

diff --git a/shitpost b/shitpost
index 8710946..2313d66 100755
--- a/shitpost
+++ b/shitpost
@@ -34,12 +34,13 @@ OPTIND=1
 top_text=" "
 bottom_text=" "
 image_file=""
+output_file=""

-while getopts "h?t:b:f:" opt; do
+while getopts "h?t:b:f:o:" opt; do

     case "$opt" in
     h|\?)
-        printf "Available options are:\n t - Top Text\n b - Bottom Text\n f - Path to image file - Mandatory!\n"
+        printf "Available options are:\n t - Top Text\n b - Bottom Text\n f - Path to image file - Mandatory!\n o - Output file\n"
         exit 0
         ;;
     t)  top_text="$OPTARG"
@@ -48,6 +49,8 @@ while getopts "h?t:b:f:" opt; do
         ;;
     f)  image_file="$OPTARG"
         ;;
+    o)  output_file="$OPTARG"
+        ;;
     esac
 done

@@ -71,30 +74,37 @@ base=${image_file##*/}
 fext=${base##*.}
 pref=${base%.*}

+if [ -z "$output_file" ]
+    then output_file="$PWD/shitpost-$pref.$fext"
+fi
+
+#Create a work directory + register cleanup for it
+tmpdir=$(mktemp -d)
+trap 'rm -rf "$tmpdir"' EXIT SIGINT
+
 #Upscale the image if it's too shitty. This is required to make the text readable as it's generated to fit the pixels of the original
-convert -resize 1024x1024\< "$image_file" shitpost-temp-resize.png
+convert -resize 1024x1024\< "$image_file" "$tmpdir"/shitpost-temp-resize.png

 #Get the height and width of the image to use later to size the overlays. Clipped height keeps things locked in the top and bottom fifth of the image.
-image_width=`identify -format "%[width]" shitpost-temp-resize.png`
-image_height=`identify -format "%[height]" shitpost-temp-resize.png`
+image_width=$(identify -format "%[width]" "$tmpdir"/shitpost-temp-resize.png)
+image_height=$(identify -format "%[height]" "$tmpdir"/shitpost-temp-resize.png)
 clipped_height=$(($image_height/5))
 stroke_width=$(($clipped_height/40))

+printf "Working"

-convert -background none -fill white -stroke black -strokewidth "$stroke_width" -size "$image_width"x"$clipped_height" -gravity Center -font 'Impact' caption:"$top_text" temp-top-text.png
-convert -background none -fill white -stroke black -strokewidth "$stroke_width" -size "$image_width"x"$clipped_height" -gravity Center -font 'Impact' caption:"$bottom_text" temp-bottom-text.png
-composite -gravity north temp-top-text.png shitpost-temp-resize.png shitpost-temp-composite.png
-composite -gravity south temp-bottom-text.png shitpost-temp-composite.png shitpost-"$pref"."$fext"
-
+convert -background none -fill white -stroke black -strokewidth "$stroke_width" -size "$image_width"x"$clipped_height" -gravity Center -font 'Impact' caption:"$top_text" "$tmpdir"/temp-top-text.png
+printf "."
+convert -background none -fill white -stroke black -strokewidth "$stroke_width" -size "$image_width"x"$clipped_height" -gravity Center -font 'Impact' caption:"$bottom_text" "$tmpdir"/temp-bottom-text.png
+printf "."
+composite -gravity north "$tmpdir"/temp-top-text.png "$tmpdir"/shitpost-temp-resize.png "$tmpdir"/shitpost-temp-composite.png
+printf "."
+composite -gravity south "$tmpdir"/temp-bottom-text.png "$tmpdir"/shitpost-temp-composite.png "$output_file"
+printf ".\n"

-#Clean up
-rm temp-top-text.png
-rm temp-bottom-text.png
-rm shitpost-temp-resize.png
-rm shitpost-temp-composite.png

 #Announce the results
-echo "Created file "$PWD"/shitpost-"$pref"."$fext""
+echo "Created file $output_file"

 exit 0
-#End
\ No newline at end of file
+#End