我制作了一个很酷的小脚本来拍摄我的大量 JPG/PNG/CR2(原始文件)照片集,并将它们转换为 2880 像素 JPEG 的 MacBook Pro Retina 分辨率。
这使我可以将所有照片保存在计算机上,同时将巨大的原件存储在外部硬盘驱动器上。最好的照片看起来很棒,因为它们已调整到我的确切物理屏幕分辨率 2880 像素宽!
您可以轻松地根据自己的需要调整脚本...
好的等等我的问题....
我的外部硬盘驱动器上的图片存储如下:
(硬盘根目录)
图片
2013-05 佛蒙特州婚礼
img_0001.jpg
img_0002.jpg
2014-10 拉斯维加斯之旅
img_0001.cr2
img_0002.cr2
...
现在脚本覆盖了原始文件......所以我总是需要将所有图片的完整副本复制到第二个驱动器,然后运行脚本。是否有一种简单的方法可以使脚本重新创建整个目录结构并将新文件写入新文件夹/驱动器,同时保持目录结构?
感谢您的帮助!
##################################
#!/bin/bash - resize2880px.sh (It's for Mac OS X computers)
# By Jason Fox of GetFoxy.com 2014 - hit me at jfox {at} foxnv.com if you have questions
# This script converts all PNG/JPG/CR2 files to JPG at a max resolution of 2880px (saving tons of space in the process).
# run it like this:
# 0. Save this script in your Documents Folder as resize2880px.sh
# 1. Open Terminal and CD into the directory of pictures to shrink
# 2. paste in: find . -type f \( -iname "*.png" -o -iname "*.jpg" -o -iname "*.cr2" \) -exec sh ~/Documents/resize2880px.sh {} \;
# 3. If you have the awesome JPEGMini app... use it now to further save space! ;)
#the sizes to convert to
width=2880
height=2880
#theFile given in input
theFile=$1
echo ""
echo "$theFile"
#using sips to retrieve the width & height
#size[0] = width
#size[1] = height
size=($(sips -g pixelWidth -g pixelHeight "$theFile" | grep -o '[0-9]*$'))
if [[ ${size[0]} -le $width && ${size[1]} -le $height ]];
then echo "Width = ${size[0]} & Height = ${size[1]} SO... W<=$width H<=$height - no resize - just JPG convert"
sips -s format jpeg "$theFile" --out "$theFile-t2880px.jpg"
elif [[ ${size[0]} -gt $width && ${size[1]} -le $height ]];
then echo "Width = ${size[0]} & Height = ${size[1]} SO... W>$width H<=$height - Run SIPS $width JPG conversion"
sips -Z 2880 -s format jpeg "$theFile" --out "$theFile-t2880px.jpg"
elif [[ ${size[0]} -le $width && ${size[1]} -gt $height ]];
then echo "Width = ${size[0]} & Height = ${size[1]} SO... W<=$width H>$height - Run SIPS $width JPG conversion"
sips -Z 2880 -s format jpeg "$theFile" --out "$theFile-t2880px.jpg"
elif [[ ${size[0]} -gt $width && ${size[1]} -gt $height ]];
then echo "Width = ${size[0]} & Height = ${size[1]} SO... W>$width H>=$height - Run SIPS $width JPG conversion"
sips -Z 2880 -s format jpeg "$theFile" --out "$theFile-t2880px.jpg"
else echo "Something is wrong."
fi
# Determine number of file system blocks used to store the original and new files
origfilesize=$(ls -s "$theFile" | awk '{print $1}')
newfilesize=$(ls -s "$theFile-t2880px.jpg" | awk '{print $1}')
if [[ $origfilesize -le $newfilesize ]];
then echo "$origfilesize is less than or equal to $newfilesize - no space saved so deleting the new file"
rm "$theFile-t2880px.jpg"
else
echo "$origfilesize is greater than $newfilesize - deleting original file"
rm "$theFile"
fi