LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Blogs > rainbowsally
User Name
Password

Notices

Rate this Entry

KDE Utils: new.image <format>

Posted 01-19-2012 at 10:21 PM by rainbowsally
Updated 01-19-2012 at 10:32 PM by rainbowsally

More 'new' funcs for KDE. Most of these will work with other Window managers but some rely on KDE gui apps so we'll call these KDE utilities.

--------------------
These posts may also be of interest or may fill in some blanks if any of this post seems to be missing some pieces.

Personal HOME/bin installer/uninstaller, no superuser req'd here and reason for 'new(dot)' file (or file set) creation:
http://www.linuxquestions.org/questi...-tofile-34376/

Desktop terminal here:
http://www.linuxquestions.org/questi...ec#post4575942

Possibly also "Let's Go Retro Now" (better kolourpaint if you need it) here:
http://www.linuxquestions.org/questi...ing-how-34378/
--------------------

How do we create a new image in the current directory? We don't have a right-click menu item for generating these, so let's make a next best, or better option.

I'll put this utility here for reasons explained in previous posts.
Code:
HOME/bin/src/new-image
                +-- new.image (executable)
                +-- img-formats (formats we will be able to list & generate)
                      +-- template files
Here's the help/usage text.

file: <path>/new-image/new-image.txt
Code:
Usage:
  new.image [ <name.ext> | --help ]
  
  Creates a new 32x32 image file named <name.ext> of a type determined by
  <ext>.  
  
  To see a list of file types available type 
    new.image --types
  
  To see this help type
    new.image --help
The advantage of doing the help/usage display this way (as a regular text file) is that what you see is what is displayed when the --help switch is invoked. The disadvantage is that you can't use env vars to pass string variables around such as the app name, version, paths, etc.

Here's the application.
file: <path>/new-image/new.image (that's a dot in the filename)

Code:
#!/bin/sh

HERE=$PWD

APPPATH=`readlink "$0"`
if [ "$APPPATH" = "" ]; then
  APPPATH="$0"
fi

THERE=`dirname "$APPPATH"`

FMTLIST=

cd $THERE
for i in `ls img-formats/a.*`; do
  FMTLIST=`printf "%s\n%s" "$FMTLIST" "$i" | sed '/^$/d; s|^.*/a\.||;'"  "`
done
cd $HERE

print_types()
{
echo "
Available image formats:

$FMT
"
}

print_usage()
{
echo "
Usage:
  new.image [ <name.ext> | --help ]
  
  Creates a new 32x32 image file named <name.ext> of a type determined by
  <ext>.  
  
  To see a list of file types available type 
    new.image --types
  
  To see this help type
    new.image --help   
"
}

if [ "$1" = "" ]; then
  print_usage
elif [ "$1" = "--help" ]; then
  print_usage
elif [ "$1" = "--types" ]; then
  print_types
else
  EXT=`echo "$1" | sed 's|^.*\.||'`
  cp $THERE/img-formats/a.$EXT $HERE/$1
fi
I use the generic /bin/sh to call my shell. If you use kubuntu, this shell is DASH by default, but that will cause you all kinds of problems, especially if you ever try to compile anything, so we assume that sh --> bash in these posts.

Or if you insist you can change the /bin/sh line to /bin/bash.

Whatever works.

The file above needs to be made executable and symlinked into your path. See 'new.symlink' in previous posts and notes on installation/uninstallation if this seems odd to you. ;-)

To install it cd to the directory containing the executable and type.
Code:
new.symlink new.image ~/bin
as per the other utilities.

Now we need the first image. Let's make it a blank 32x32 pixel image such as might be used in a menu, or just for a seed to begin creating a new image with a spraycan or whatever your favorite art tools may be.

Create the 'img-formats' directory under the containing folder and add this.

file: <path>/new-image/img-formats/a.xpm
Code:
/* XPM */
static char *dummy[]={
"32 32 1 1",
". c #ffffff",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................",
"................................"};
Once created, you can open the file with an image editor such as kolourpaint (see "Let's Go Retro Now" post if you need a kolourpaint that works better than what you may have) and 'save as' any format you wish to be able to generate.

To test, open a terminal on your Desktop (such as the one shown in the links at the top which WILL open on your Desktop) and type
Code:
new.image --types
Each format you've created should be listed. Let's assume you have made yourself a 'png' template using 'save as' and selecting 'png'.

Type
Code:
new.image png
And the png file names 'a.png' should appear on your desktop.

The svg format used by inkscape is a bit trickeir because it may be a collection of images that are linked into the svg file with absolute paths so it needs a bit of processing to make the svg file and files it references relocatable.

We'll do that "tricky" svg format a bit later.

[Note: This HOME/bin repository of scripts and programs we are building can be viewed in your 'edit'or and, as a set of tested/working snippets, may save you a lot of time when creating other applications.]

.
Posted in Uncategorized
Views 641 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 07:30 AM.

Main Menu
Advertisement

My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration