利器: Mac自带的图片工具Sips
,全部的用法可以参考:
sips MAN page Man Page - macOS - SS64.com
以下就是引用
利器: Mac自带的图片工具Sips
内容:
1.裁剪时固定图片宽度,高度自适应
1
| sips -Z 320 iamge_file_name
|
2.裁剪时指定图片宽与高
1 2
| # 裁剪图片为400x300大小 sips -z 400 300 iamge_file_name
|
注:需要注意的是这里的参数是小写的z,并且图片缩放方式不是锁定图片比例的,即如果图片本身是16:9,则会导致图片被挤压。
3.旋转图片
1
| sips -r 90 image_file_name
|
注:上面的命令将图片顺时针旋转90度,相信机智的你已经想到逆时针90度应该是-90了。没错,顺时针用正数表示,逆时针可以用负数表示。你可以进行任意角度和方向的旋转。
4.翻转图片
1
| sips -f horizontal image_file_name
|
注:上面命令可以对图片进行水平翻转,-f支持水平和垂直两种翻转,水平(horizontal),垂直(vertical)。
5.修改图片格式
1
| sips -s format jpeg input.png --out output.jpg
|
注:使用-s参数可以修改图片格式为指定值,sips支持jpeg | tiff | png | gif | jp2 | pict | bmp | qtif | psd | sgi | tga共11种格式。并且-s除了能修改文件格式外,还能修改图片的其它meta数据,具体可以通过man sips查看。
6.获取图片meta信息
1
| sips -g pixelWidth -g pixelHeight image_file_name
|
注:上面命令可以获取图片的长宽高信息,与-s参数一样,-g也支持更多的meta值,可以参见man sips的信息,这里就不做赘述了。
iHTCboy/iShell: Shell脚本编程技巧,总结一些常用的提高效率的方法。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #!/bin/bash
# 定义用到的变量 imagePath="" angle=""
# 定义读取输入字符的函数
getImagePath() { echo "\n================================================" # 监听输入并且赋值给变量 read -p "Enter image path: " imagePath # 如果为空值,从新监听,否则执行旋转函数 if test -z "$imagePath"; then getImagePath else rotationImage fi }
rotationImage() { echo "\n================================================" read -p "Enter angle(default 90°): " angle # 如果为空值,默认设置为90度 if test -z "$angle"; then angle="90" fi
# 使用 sips 命令进行图片旋转 sips -r "${angle}" "${imagePath}" echo "\n rotation $angle ° finished!" # 重新调用旋转函数,方便多次旋转操作 rotationImage }
# 首先执行函数,给变量赋值 getImagePath
|
使用sips命令自动缩减图片尺寸
下一节,结合刚需,打算写一个从一张1024的图片,自动生成Xcode所需要的全部图标,这应该是一个不错的想法!期待吧~
利器: Mac自带的图片工具Sips
sips MAN page Man Page - macOS - SS64.com
使用sips命令自动缩减图片尺寸
shell技巧1 - 生成ipa文件 | iHTCboy’s blog
缺失模块。
1、请确保node版本大于6.2
2、在博客根目录(注意不是yilia根目录)执行以下命令:
npm i hexo-generator-json-content --save
3、在根目录_config.yml里添加配置:
jsonContent:
meta: false
pages: false
posts:
title: true
date: true
path: true
text: false
raw: false
content: false
slug: false
updated: false
comments: false
link: false
permalink: false
excerpt: false
categories: false
tags: true