-1

I'm having some pixmaps like this (36, to be exact):

/* 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",
"            ",
"            ",
"            ",
"            ",
" ....++.... ",
" ....++.... ",
" .......... ",
" .......... ",
" ++++++++++ ",
" ++++++++++ ",
" .......... ",
" .......... ",
" ....++.... ",
" ....++.... "};

I want to make it 4 times bigger (twice horizontally and twice vertically). I can't use a image editor because the colors are define for Gtk color picking and it'd take too much time to edit that much of images. So could you write me a command/script that duplicate all pixels and duplicate all pixels lines (from line 7), with several files? I mean, a command/script can transform this:

/* XPM */
static char * hide_active_xpm[] = {
"4 3 2 1",
".  c #EDEDED s active_color_2",
"+  c #313739 s active_text_color_2",
"+...",
".++.",
"+.+."};

to this:

/* XPM */
static char * hide_active_xpm[] = {
"8 6 2 1",
".  c #EDEDED s active_color_2",
"+  c #313739 s active_text_color_2",
"++......",
"++......",
"..++++..",
"..++++..",
"++..++..",
"++..++.."};

Thank you very much for checking out my problem.

McSinyx

  • 3
    You wrote: "it'd take too much time to edit that much of images. So could you write me a command/script" - Do you realise how rude that is? - What have you tried so far? What were your concrete problems? – Janis May 28 '15 at 15:13
  • 1
    Sorry if it does really sound rude, I didn't mean to be, but my English is far to be good, so I guess there is a mistake in describing the case and asking for help there. Well, a X Pixmap with non-standard colors can't be opened by gimp (all colors go wrong - please tell me if there is another image editor that can), so edit all colors, then open them, do the resize, then edit all colors wouldn't be the best choice (I'll do it, if can't get no help here). – McSinyx May 29 '15 at 11:01
  • It's okay @McSinyx. You're new here. However, do read the guidelines. For starters, keep 2 things in mind whenever you ask a question : 1) Explain well 2) Show that you have done some effort from your side. Also, NEVER ask questions answers to which might be a google search away. – shivams May 29 '15 at 11:47
0

The following script will take your .xpm file as input and print the new desired output.

#!/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; 

The new desired output will be printed to the screen. To print the output to a file:

./enlarge.sh input.xpm > new.xpm

Important Note

The script is based on sed regex. This can be highly unreliable in cases where, say the text is distributed between multiple lines. If you just want to enlarge the images to double the size, then why not use mogrify? Usage is:

 mogrify -scale 200% image.xpm
  • Thank you, it works (though a bit buggy)! – McSinyx May 29 '15 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.