1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

完全に理解した Slack 絵文字を作った

Last updated at Posted at 2021-04-13

メガ文字でやり方わからなかったので作った。

https://zk-phi.github.io/MEGAMOJI/

こんなの
scroll.gif
kanzen.gif
完全に理解した!-#FFFFFF-#00FFFF.gif

出典
https://yingtongli.me/blog/2018/05/12/marquee.html

  1. brew install ffmpeg gifsicle
  2. FONT_PATH を合わせる
  3. 実行

slackのemojiが130KBあたりに制限があるらしいので、大きすぎる場合は 32x32くらいにするといいかも。

自分の環境だとFILL色が効いてないです。

#!/bin/bash

IMWIDTH=48
IMHEIGHT=48
STEP=5 #pixels per frame
FRAMERATE=50 #frames per second

FONT_PATH="/System/Library/Fonts/ヒラギノ角ゴシック W4.ttc"

MESSAGE="完全に理解した"

BACKGROUND="#FFFFFF"
FILL="#00FFFF"

# Make a "unique" prefix for this run
PREFIX="$(head -c 32 /dev/urandom  | shasum | cut -b 1-10)"
OUTPUT="${PREFIX}.gif"
OUTPUT="scroll.gif"

# Generate image from text input
convert -background "$BACKGROUND" -fill "$FILL" -font "$FONT_PATH" -density 200 -pointsize 100 "label:${MESSAGE}" "/tmp/${PREFIX}_label.png"

# Resize to 128px high
convert -resize x${IMHEIGHT} "/tmp/${PREFIX}_label.png" "/tmp/${PREFIX}_sized.png"

# Add white space to front and back for empty frames
WIDTH="$(identify -format "%[fx:w]" "/tmp/${PREFIX}_sized.png")"
CANVAS_SIZE=$(($WIDTH + $IMWIDTH + $IMWIDTH))
echo width=$WIDTH
echo CANVAS_SIZE=$CANVAS_SIZE
convert -size ${CANVAS_SIZE}x${IMHEIGHT} "xc:$BACKGROUND" "/tmp/${PREFIX}_canvas.png"
convert "/tmp/${PREFIX}_canvas.png" "/tmp/${PREFIX}_sized.png" -geometry +${IMWIDTH}+0 -composite "/tmp/${PREFIX}_padded.png"

# Generate individual frames
OFFSET=0
I=0
LIMIT=$(($CANVAS_SIZE - $IMWIDTH))
while [ $OFFSET -lt $LIMIT ]; do
  echo ${OFFSET}/${LIMIT}
  convert "/tmp/${PREFIX}_padded.png" -crop "${IMWIDTH}x${IMHEIGHT}+${OFFSET}+0!" "PNG32:$(printf "/tmp/${PREFIX}_frame_%05d.png" $I)"
  I=$(($I + 1))
  OFFSET=$(($OFFSET + $STEP))
done

# Compile to gif
ffmpeg -y -f image2 -i "/tmp/${PREFIX}_frame_%05d.png" -vf palettegen "/tmp/${PREFIX}_frame_palette.png"
ffmpeg -y -f image2 -framerate $FRAMERATE -i "/tmp/${PREFIX}_frame_%05d.png" -i "/tmp/${PREFIX}_frame_palette.png" -filter_complex "[0:v][1:v]paletteuse" "$OUTPUT"

# Compress it
# gifsicle -bO --dither --colors 8 "$OUTPUT"

# Clean up!
rm /tmp/${PREFIX}_*.png
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?