sh 将图像重新分辨为16:9分辨率,1080p(1920 x 1080),1440p(2560 x 1440)或4K(3840 x 2160)。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh 将图像重新分辨为16:9分辨率,1080p(1920 x 1080),1440p(2560 x 1440)或4K(3840 x 2160)。相关的知识,希望对你有一定的参考价值。
/#!/usr/bin/bash
# Recrops images in working directory to 16:9 resolution.
# Picks the smallest resolution which fits the image with minimal cropping.
OUTPUT_DIR="recropped"
EXT="jpg"
mkdir -p "$OUTPUT_DIR"
for file in *.$EXT; do
echo "$OUTPUT_DIR/$file"
touch "$OUTPUT_DIR/$file"
WIDTH=`identify -ping -format "%w" "$file"`
HEIGHT=`identify -ping -format "%h" "$file"`
let "IDEAL_WIDTH = $HEIGHT * 16 / 9"
let "IDEAL_HEIGHT = $WIDTH * 9 / 16"
echo $WIDTH, $HEIGHT, $IDEAL_WIDTH, $IDEAL_HEIGHT
# Max height / width restrictions
if [ "$WIDTH" -gt 3840 ] || [ "$HEIGHT" -gt 2160 ]; then
convert "$file" -background black -gravity center -extent 3840x2160 -flatten "$OUTPUT_DIR/$file"
# Too wide -> add black bars on top / bottom
elif [ $IDEAL_WIDTH -ge $WIDTH ]; then
convert "$file" -background black -gravity center -extent "${IDEAL_WIDTH}x${HEIGHT}" -flatten "$OUTPUT_DIR/$file"
# Too narrow -> add black bars on sides
else
convert "$file" -background black -gravity center -extent "${WIDTH}x${IDEAL_HEIGHT}" -flatten "$OUTPUT_DIR/$file"
fi
## Old algorithm: resize to standard sizes of 1080p, 1440p, 4K
# if [ "$WIDTH" -gt 2560 ] || [ "$HEIGHT" -gt 1440 ]; then
# convert "$file" -background black -gravity center -extent 3840x2160 -flatten "$OUTPUT_DIR/$file"
# elif [ "$WIDTH" -gt 1920 ] || [ "$HEIGHT" -gt 1080 ]; then
# convert "$file" -background black -gravity center -extent 2560x1440 -flatten "$OUTPUT_DIR/$file"
# else
# convert "$file" -background black -gravity center -extent 1920x1080 -flatten "$OUTPUT_DIR/$file"
# fi
done
以上是关于sh 将图像重新分辨为16:9分辨率,1080p(1920 x 1080),1440p(2560 x 1440)或4K(3840 x 2160)。的主要内容,如果未能解决你的问题,请参考以下文章
iOS视频编辑SDK
分辨率
VM虚拟机安装Linux Deepin,却在系统设置中找不到分辨率为1920*1080这项,求解如何将分辨率改为1080p
720P1080P4K是什么意思?
显示屏分辨率和接口
macbook如何录屏?Mac电脑录屏导出黑边如何解决