简体   繁体   English

使用命令行向图像添加透明像素线

[英]Add lines of transparent pixels to image using command line

I have a few 15x15 PNGs that I need to convert to 18x18 PNGs. 我有几个15x15的PNG,我需要转换为18x18的PNG。

However, I don't want to simply scale the entire image up. 但是,我不想简单地缩放整个图像。

What I want is basically keep the exact old image, but "pad" it with lines of invisible/transparent pixels. 我想要的基本上是保留精确的旧图像,但用不可见/透明像素线“填充”它。

So let's say the original image looked like this (imagine the X s are pixels): 所以让我们说原始图像看起来像这样(想象X是像素):

XXXX
XXXX
XXXX
XXXX

I want to turn it into something like this ( X being pixels of original image, T being new transparent pixels): 我想把它变成这样的东西( X是原始图像的像素, T是新的透明像素):

XXXXT
XXXXT
XXXXT
XXXXT
TTTTT

Is this possible using command-line tools (so that this can be automated), perhaps with something like imagemagick? 这可能是使用命令行工具(这样可以自动化),也许像imagemagick?

这将完成工作:

convert input_file -background transparent -extent '18x18' output_file

You can do that with ImageMagick's -append and +append operators. 您可以使用ImageMagick的-append+append运算符来实现。 -append appends to the vertically (bottom), +append appends horizontally (right): -append追加到垂直(底部), +append追加到水平(右):

convert \
  -background transparent \
   15x15.png \
   null: null: null: +append \
   null: null: null: -append \
   18x18.png

The null: picture is an ImageMagick built-in: it represents a 1 transparent pixel. null:图片是内置的ImageMagick:它代表1个透明像素。

But as usually is the case with IM: there are a thousand ways to reach the same goal. 但正如IM的情况一样:有一千种方法可以达到同一目标。

Should you ever need to add the transparent parts to the left and top (instead of the right and bottom), or should you want to add the pixels to just one, or to three or to four (instead of only two edges, it should be obvious to you how to modify my command. 您是否需要将透明部分添加到左侧和顶部(而不是右侧和底部),或者您是否要将像素添加到一个,或三个或四个(而不是仅两个边缘,它应该很明显你如何修改我的命令。

Maybe you find Theodros' answer more intuitive (+1 on for it!). 也许你会发现Theodros的答案更直观(+1就可以了!)。 In this case, should you want to change the borders where you add your pixels, you can add the -gravity parameter to his command: 在这种情况下,如果要更改添加像素的边框,可以将-gravity参数添加到其命令中:

convert infile -background transparent -gravity southeast -extent '18x18' outfile

Other than south , you can also use north , northeast , east , ... and northwest . 除了south ,您还可以使用northnortheasteast ,......和northwest Not to forget center ... 不要忘记center ......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用命令行将文件添加到 macOS 上的 Dock - Add files to Dock on macOS using the command line 命令行将所有图像的视网膜显示扩展名添加到文件夹中 - Command line Add retina display extension to all image into a folder 使用终端在python中找到图像像素? - find image pixels in python using Terminal? 使用Mac命令行工具将一个图像插入另一个图像 - Insert one image into another using a mac command line tool 使用命令行将zip文件从一个存档添加到另一个存档 - Add zip files from one archive to another using command line Swift 命令行工具 - 读取多行 - Swift Command Line Tool - Read multiple lines 如何在“Mac 终端”中使用“console.log”和 NodeJS 中的命令行“Local heroku”显示多行? - How display multiple lines in the "Mac Terminal" using "console.log" with the command line "Local heroku" in NodeJS? 使用'android'命令行实用程序定位特定的系统映像版本? - Targeting a specific system-image version using the 'android' command line utility? 在osx命令行中使用Mysql - 找不到命令? - Using Mysql in the command line in osx - command not found? 如何使用“ git credential-osxkeychain store”从命令行添加凭据? - how to add credentials from the command line using 'git credential-osxkeychain store'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM