我有一些像这样的像素图(确切地说是 36 个):
/* XPM */
static char * hide_active_xpm[] = {
"12 14 3 1",
" c None",
". c #EDEDED s active_color_2",
"+ c #313739 s active_text_color_2",
" ",
" ",
" ",
" ",
" ....++.... ",
" ....++.... ",
" .......... ",
" .......... ",
" ++++++++++ ",
" ++++++++++ ",
" .......... ",
" .......... ",
" ....++.... ",
" ....++.... "};
我想让它变大 4 倍(水平两倍,垂直两倍)。我无法使用图像编辑器,因为颜色是为 Gtk 颜色选择定义的,并且编辑这么多图像需要太多时间。那么你能给我写一个命令/脚本吗复制所有像素和复制所有像素线(从第 7 行开始),有几个文件?我的意思是,命令/脚本可以改变这一点:
/* XPM */
static char * hide_active_xpm[] = {
"4 3 2 1",
". c #EDEDED s active_color_2",
"+ c #313739 s active_text_color_2",
"+...",
".++.",
"+.+."};
对此:
/* XPM */
static char * hide_active_xpm[] = {
"8 6 2 1",
". c #EDEDED s active_color_2",
"+ c #313739 s active_text_color_2",
"++......",
"++......",
"..++++..",
"..++++..",
"++..++..",
"++..++.."};
非常感谢您检查我的问题。
麦西尼克斯
答案1
以下脚本将把您的.xpm
文件作为输入并打印新的所需输出。
#!/bin/bash
#enlarge.sh
cat "$1" | while read -r line;
do
if echo "$line" | grep -vP "[[:alnum:]]" 1>/dev/null;
then
#The following line is applies to all pixel lines except the very last one
echo "$line" | sed 's/\(\+\|\.\)/&&/g;p' | grep -vP "\}\;$" || \
#The following line applies to the last one with "};" characters in the end
echo "$line" | sed 's/\(\+\|\.\)/&&/g' | sed 's/\}\;$/,/g' | sed 'p;s/\,$/\}\;/g'
else
echo "$line"
fi;
done;
新的所需输出将打印到屏幕上。要将输出打印到文件:
./enlarge.sh input.xpm > new.xpm
重要的提示
该脚本基于 sed 正则表达式。在文本分布在多行之间的情况下,这可能非常不可靠。如果您只想将图像放大一倍,那么为什么不使用 呢mogrify
?用法是:
mogrify -scale 200% image.xpm