⚠️ 这是一个非官方翻译网站,与 ImageMagick Studio LLC 无关。准确信息请参阅原文(https://imagemagick.org/magick/)

magick

使用 magick 程序可以在各种图像格式之间转换,还可以调整尺寸、模糊、裁剪、去斑、抖动、绘制、翻转、拼接、重采样等等。关于如何组织 magick 命令的建议,请参阅命令行处理,或查看下面的命令使用示例。

我们在这里列举几个 magick 命令的示例,以说明它的实用性和易用性。作为开始,让我们把 JPEG 格式的图像转换为 PNG:

magick rose.jpg rose.png

接下来,在写入 PNG 格式之前先缩小图像尺寸:

magick rose.jpg -resize 50% rose.png

rose ==> rose

你可以组合多个图像处理操作,生成复杂的效果:

magick -size 320x85 canvas:none -font Bookman-DemiItalic -pointsize 72 \
  -draw "text 25,60 \'Magick\'" -channel RGBA -blur 0x6 -fill darkred -stroke magenta \
  -draw "text 20,55 \'Magick\'" fuzzy-magick.png

fuzzy-magick

或者在提高质量的同时调整图像尺寸:

magick input.png -colorspace RGB +sigmoidal-contrast 11.6933 \
  -define filter:filter=Sinc -define filter:window=Jinc -define filter:lobes=3 \
  -resize 400% -sigmoidal-contrast 11.6933 -colorspace sRGB output.png');

你可以通过 magick 工具调用其他命令行工具。要使用此功能,只需创建一个指向 magick 工具的符号链接,或者把想要使用的工具作为第一个参数指定。以下两种方式是等价的:

ln -s magick identify
identify rose.jpg rose.png
magick identify rose.jpg rose.png

更多 magick 使用示例可在 Examples of ImageMagick Usage 中找到。

选项一览

magick 命令可识别以下选项。点击某个选项可查看其工作方式的详细信息。

-adaptive-blur geometry 自适应地模糊像素;在边缘附近减弱效果
-adaptive-resize geometry 通过数据相关的三角剖分自适应地调整图像尺寸
-adaptive-sharpen geometry 自适应地锐化像素;在边缘附近增强效果
-adjoin 将多个图像合并为单个多图像文件
-affine matrix 仿射变换矩阵
-alpha alpha 通道的 on, activate, off, deactivate, set, opaque, copy, transparent, extract, background, shape 设置
-annotate geometry text 用文本为图像添加注释
-antialias 去除像素锯齿
-append 连接图像序列
-authenticate value 用此密码解密图像
-auto-gamma 自动调整图像的伽马级别
-auto-level 自动调整图像的色阶
-auto-orient 自动校正图像方向
-background color 背景色
-bench iterations 测量性能
-bias value 在对图像做卷积时添加偏置
-bilateral-blur geometry 非线性、保边、降噪的平滑滤镜
-black-threshold value 强制所有低于阈值的像素变为黑色
-blue-primary point 色度蓝原色点
-blue-shift factor 模拟月光下的夜间场景
-blur geometry 降低图像噪声并减少细节层次
-border geometry 用彩色边框环绕图像
-bordercolor color 边框颜色
-brightness-contrast geometry 改善图像的亮度/对比度
-canny geometry 使用多阶段算法检测图像中范围广泛的边缘
-caption string 为图像指定标题
-cdl filename 用颜色决策列表进行颜色校正
-channel type 将选项应用于选定的图像通道
-charcoal radius 模拟炭笔画
-chop geometry 移除图像内部的像素
-clahe geometry 对比度受限的自适应直方图均衡化
-clamp 将值低于零的每个像素设为零,将值高于量化范围的像素设为量化范围(例如 65535),否则像素值保持不变
-clip 沿 8BIM 配置文件中的第一条路径进行裁剪
-clip-mask filename 将裁剪蒙版与图像关联
-clip-path id 沿 8BIM 配置文件中的命名路径进行裁剪
-clone index 克隆图像
-clut 对图像应用颜色查找表
-connected-components connectivity 为连通分量赋予唯一标记,可选 4 连通或 8 连通
-contrast-stretch geometry 通过“拉伸”强度值范围来改善图像对比度
-coalesce 合并图像序列
-colorize value 用填充色为图像着色
-color-matrix matrix 对图像应用颜色校正
-colors value 图像中首选的颜色数量
-colorspace type 设置图像色彩空间
-combine 组合图像序列
-comment string 用注释为图像添加批注
-compare 比较图像
-complexoperator 对图像序列执行复数运算
-compose operator 设置图像合成运算符
-composite 合成图像
-compress type 图像压缩类型
-contrast 增强或降低图像对比度
-convolve coefficients 对图像应用卷积核
-copy geometry offset 将像素从图像的一个区域复制到另一个区域
-crop geometry 裁剪图像
-cycle amount 循环图像的色彩映射表
-decipher filename 将加密像素转换为明文
-debug events 显示大量调试信息
-define format:option 定义一个或多个图像格式选项
-deconstruct 将图像序列分解为组成部分
-delay centiseconds 暂停后再显示下一张图像
-delete index 从图像序列中删除图像
-density geometry 图像的水平和垂直密度
-depth value 图像位深度
-despeckle 降低图像内的斑点噪声
-direction type 从右到左或从左到右渲染文本
-display server 从此 X 服务器获取图像或字体
-dispose method 图层处置方式
-distribute-cache port 启动分布式像素缓存服务器
-distort type coefficients 扭曲图像
-dither method 对图像应用误差扩散
-draw string 用图形基元为图像添加注释
-duplicate count,indexes 将图像复制一次或多次
-edge radius 应用滤镜检测图像中的边缘
-emboss radius 对图像进行浮雕处理
-encipher filename 将明文像素转换为加密像素
-encoding type 文本编码类型
-endian type 图像的字节序(MSB 或 LSB)
-enhance 应用数字滤镜来改善噪声较多的图像
-equalize 对图像执行直方图均衡化
-evaluate operator value 计算算术、关系或逻辑表达式
-evaluate-sequence operator 对图像序列计算算术、关系或逻辑表达式
-extent geometry 设置图像尺寸
-extract geometry 从图像中提取区域
-family name 用此字体族渲染文本
-features distance 分析图像特征(例如对比度、相关性等)
-fft 实现离散傅里叶变换(DFT)
-fill color 填充图形基元时使用的颜色
-filter type 调整图像尺寸时使用此滤镜
-flatten 将图像序列平整为一张
-flip 沿垂直方向翻转图像
-floodfill geometry color 用颜色对图像进行漫水填充
-flop 沿水平方向翻转图像
-font name 用此字体渲染文本
-format string 输出格式化的图像特性
-frame geometry 用装饰性边框环绕图像
-function name 对图像应用函数
-fuzz distance 在此距离内的颜色视为相等
-fx expression 对图像通道应用数学表达式
-gamma value 伽马校正的级别
-gaussian-blur geometry 降低图像噪声并减少细节层次
-geometry geometry 图像的首选尺寸或位置
-gravity type 文本的水平和垂直放置
-grayscale method 将图像转换为灰度
-green-primary point 色度绿原色点
-help 打印程序选项
-hough-lines geometry 识别图像中的直线
-identify 识别图像的格式和特性
-ift 实现逆离散傅里叶变换(DFT)
-illuminant type 参考光源
-implode amount 使像素向中心内爆
-insert index 将最后一张图像插入图像序列
-integral 计算图像中各值(像素值)的总和
-intensity method 从像素生成强度值的方法
-intent type 管理图像颜色时的渲染意图类型
-interlace type 图像隔行扫描方案的类型
-interline-spacing value 两行文本之间的间距
-interpolate method 像素颜色插值方法
-interword-spacing value 两个单词之间的间距
-kerning value 两个字符之间的间距
-kuwahara geometry 保边的降噪滤镜
-label string 为图像指定标签
-lat geometry 局部自适应阈值处理
-layers method 优化或比较图像图层
-level value 调整图像对比度的级别
-limit type value 像素缓存资源上限
-linear-stretch geometry 带饱和的线性直方图拉伸
-liquid-rescale geometry 用接缝裁剪重新缩放图像
-list type Color, Configure, Delegate, Format, Magic, Module, Resource 或 Type
-log format 调试信息的格式
-loop iterations 为你的 GIF 动画添加 Netscape 循环扩展
-mask filename 将蒙版与图像关联
-mattecolor color 框架颜色
-median radius 对图像应用中值滤镜
-mean-shift geometry 勾勒图像中任意形状的聚类
-metric type 用此指标测量图像之间的差异
-mode radius 将每个像素设为邻域的“主导颜色”
-modulate value 改变亮度、饱和度和色相
-moments 显示图像矩
-monitor 监视进度
-monochrome 将图像转换为黑白
-morph value 对图像序列进行变形
-morphology method kernel 对图像应用形态学方法
-motion-blur geometry 模拟运动模糊
-negate 用补色替换每个像素
-noise radius 在图像中添加或降低噪声
-normalize 将图像扩展到整个颜色范围
-opaque color 将此颜色更改为填充色
-ordered-dither NxN 对图像进行有序抖动
-orient type 图像方向
-page geometry 图像画布的尺寸和位置(设置)
-paint radius 模拟油画
-perceptible 将值小于
-ping 高效地确定图像属性
-pointsize value 字体磅值大小
-polaroid angle 模拟宝丽来照片
-poly terms 从图像序列和对应的项(系数与次数对)构建多项式
-posterize levels 将图像减少到有限数量的色阶
-precision value 设置要打印的最大有效位数
-preview type 图像预览类型
-print string 解释字符串并打印到控制台
-process image-filter 用自定义图像滤镜处理图像
-profile filename 添加、删除或应用图像配置文件
-quality value JPEG/MIFF/PNG 压缩级别
-quantize colorspace 在此色彩空间中减少图像颜色
-quiet 抑制所有警告消息
-rotational-blur angle 径向模糊图像
-raise value 通过加亮/变暗图像边缘营造 3D 效果
-random-threshold low,high 对图像进行随机阈值处理
-red-primary point 色度红原色点
-regard-warnings 重视警告消息
-region geometry 将选项应用于图像的某一部分
-remap filename 将图像颜色变换为匹配此颜色集合
-render 渲染矢量图形
-repage geometry 图像画布的尺寸和位置
-resample geometry 更改图像的分辨率
-reshape geometry 重塑图像
-resize geometry 调整图像尺寸
-respect-parentheses 设置在括号边界之前保持有效
-roll geometry 垂直或水平地滚动图像
-rotate degrees 对图像应用 Paeth 旋转
-sample geometry 用像素采样缩放图像
-sampling-factor geometry 水平和垂直采样系数
-scale geometry 缩放图像
-scene value 图像场景编号
-seed value 为新的伪随机数序列设置种子
-segment values 对图像进行分割
-selective-blur geometry 选择性地模糊对比度阈值内的像素
-separate 将图像通道分离为灰度图像
-sepia-tone threshold 模拟棕褐色调照片
-set attribute value 设置图像属性
-shade degrees 用远处光源为图像添加阴影
-shadow geometry 模拟图像阴影
-sharpen geometry 锐化图像
-shave geometry 从图像边缘削去像素
-shear geometry 沿 X 轴或 Y 轴滑动图像的一条边
-sigmoidal-contrast geometry 在不使高光或阴影饱和的情况下增加对比度
-smush offset 将图像序列紧贴拼接在一起
-size geometry 图像的宽度和高度
-sketch geometry 模拟铅笔素描
-solarize threshold 反转所有高于阈值级别的像素
-sort-pixels 按强度升序对每条扫描线内的像素进行排序
-splice geometry 将背景色插入图像
-spread radius 将图像像素随机位移一定量
-statistic type geometry 用邻域中对应的统计值替换每个像素
-strip 从图像中剥离所有配置文件和注释
-stroke color 图形基元的描边颜色
-strokewidth value 图形基元的描边宽度
-stretch type 用此字体伸缩渲染文本
-style type 用此字体样式渲染文本
-swap indexes 交换图像序列中的两张图像
-swirl degrees 使图像像素围绕中心旋转
-synchronize 将图像同步到存储设备
-taint 将图像标记为已修改
-texture filename 平铺到图像背景上的纹理名称
-threshold value 对图像进行阈值处理
-thumbnail geometry 创建图像的缩略图
-tile filename 填充图形基元时平铺图像
-tile-offset geometry 设置图像平铺偏移
-tint value 用填充色为图像染色
-transform 对图像进行仿射变换
-transparent color 使图像中的此颜色透明
-transparent-color color 透明色
-transpose 将图像垂直翻转并旋转 90 度
-transverse 将图像水平翻转并旋转 270 度
-treedepth value 颜色树深度
-trim 修剪图像边缘
-type type 图像类型
-undercolor color 注释外接框颜色
-unique-colors 对任意像素颜色仅保留一个,其余全部丢弃
-units type 图像分辨率的单位
-unsharp geometry 锐化图像
-verbose 打印图像的详细信息
-version 打印版本信息
-view FlashPix 查看变换
-vignette geometry 以渐晕风格柔化图像边缘
-virtual-pixel method 访问图像边界外像素的方法
-wave geometry 沿正弦波改变图像
-wavelet-denoise threshold 用小波变换从图像中去除噪声
-weight type 用此字体粗细渲染文本
-white-point point 色度白点
-white-threshold value 强制所有高于阈值的像素变为白色
-word-break type 设置是否在文本本应溢出内容框的位置换行。可选 normal(默认)或 break-word
-write filename 将图像写入此文件