Saturday, April 28, 2012

Gimp Script for exporting positions of all the layers.

Gimp Script for exporting positions of all the layers.


I have created a Python script which can export layer positions in a text file.

Usability:
Are you using GIMP for creating maps for your game? You want to create a 1024x768 map and put objects in it but cannot export the positions? This script can help you get the positions of your objects.

Procedure:
  1. Run GIMP and create a desired resolution image.
  2. Drag and add your object's images in gimp.
  3. Ensure that you crop the layers so that extra alpha (transparent) areas are not remained in objects.
  4. Duplicate the objects to the numbers you want and place them to positions you want.
  5.  Do same with other objects, backgrounds.
  6. Now export their positions. Filters -> Positioning -> Layers Position Dumper
  7. Put the file name with full path in next dialog. e.g. ~/my_game_map.txt in Linux Or c:\my_game_map.txt in windows. Click Ok.
  8. Now you can check the exported file which contains the positions of all the layers.

How to install the plug-in?
Firstly ensure that you have Python installed in your system. Try to install gimp until you see option of "GIMP python plugin" options checked while installation.

If you haven't installed it please install these packages, This is my installer package: gimp-2.6.11-i686-setup, python-2.5.2.msi

However you can download individual packages by google
gtk-2.12.9-win32-1.exe, pycairo-1.4.12-1.win32-py2.5.exe, pygobject-2.14.1-1.win32-py2.5.exe, pygtk-2.12.1-2.win32-py2.5.exe, python-2.5.2.msi


Or follow this page:
http://www.gimpusers.com/tutorials/install-python-for-gimp-2-6-windows


Install the plugin
Copy the python script to:
WIndows: C:\Documents and Settings\USER\.gimp-2.6\plug-ins
Linux: ~/.gimp-2.6/plug-ins
and restart gimp.

Verify that you have gimp python plugins enabled by following these steps:
Filters -> Python-Fu -> Console

type this:
>>> import gimpfu
>>> gimp.version
(2, 6, 11)


Sample exported file:


Format RATIONAL:
"layer name" X%-Pos Y%-Pos %Width %Height

Format PIXEL:
"layer name" X-Pos Y-Pos Width Height

RATIONAL: "Frame 1.png" 0.000000 0.000000 26.756757 94.634146
PIXEL:    "Frame 1.png" 0.000000 0.000000 99.000000 194.000000

RATIONAL: "Frame 2.png" 26.756757 0.000000 18.918919 99.512195
PIXEL:    "Frame 2.png" 99.000000 0.000000 70.000000 204.000000

RATIONAL: "Frame 3.png" 45.675676 0.000000 25.675676 98.048780
PIXEL:    "Frame 3.png" 169.000000 0.000000 95.000000 201.000000

RATIONAL: "Frame 5.png" 71.351351 0.000000 28.108108 97.073171
PIXEL:    "Frame 5.png" 264.000000 0.000000 104.000000 199.000000

... more dump stripped off



Download:
layer-position-dumper.7z (GIMP v2.6 & 2.8 both )

Raw code:


#!/usr/bin/env python

from gimpfu import *

gettext.install("gimp20-python", gimp.locale_directory, unicode=True)

def layer_position_dumper(img, drawable, filename):
out = file( filename,"w")
out.write( 'Developed by Bindesh Kumar Singh on 26 April 2012\n')
out.write( 'This Plugin is a utility of Greh Game Engine (C) 2009-2012\n')
out.write( 'It dumps the positions of all the layers in a specified text file\n\n')
out.write( 'Format RATIONAL:\n"layer name" X%-Pos Y%-Pos %Width %Height\n\n' )
out.write( 'Format PIXEL:\n"layer name" X-Pos Y-Pos Width Height\n\n\n\n' )
count = 0
w = float( img.width )
h = float( img.height )
for l in img.layers:
if 1 == pdb.gimp_item_is_group( l ):
#print 'group hai'
for gl in l.layers:
x = float( gl.offsets[0] ) * 100.0
y = float( gl.offsets[1] ) * 100.0
lw = float( gl.width ) * 100.0
lh = float( gl.height ) * 100.0
out.write( 'RATIONAL: "%s" %f %f %f %f\n' % ( gl.name, x / w, y / h, lw / w, lh / h ) )
out.write( 'PIXEL:    "%s" %f %f %f %f\n\n' % ( gl.name, gl.offsets[0], gl.offsets[1], gl.width, gl.height ) )
count += 1
else:
#print 'group nahin hai'
x = float( l.offsets[0] ) * 100.0
y = float( l.offsets[1] ) * 100.0
lw = float( l.width ) * 100.0
lh = float( l.height ) * 100.0
out.write( 'RATIONAL: "%s" %f %f %f %f\n' % ( l.name, x / w, y / h, lw / w, lh / h ) )
out.write( 'PIXEL:    "%s" %f %f %f %f\n\n' % ( l.name, l.offsets[0], l.offsets[1], l.width, l.height ) )
count += 1
out.close()


register(
"layer_position_dumper",
"Dump positions of the layers",
"Dumps the offsets/positions of all the layer in a specified file",
"Bindesh Kumar Singh",
"Developed for GrehGameEngine",
"2012",
"_Layers Position Dumper",
"RGB*, GRAY*",
[(PF_IMAGE, "image",       "Input image", None), (PF_DRAWABLE, "drawable", "Input drawable", None), (PF_STRING, "name",       _("_File name with full path"), _("layer_positions.txt"))],
[],
layer_position_dumper,
menu="/Filters/Positioning",
domain=("gimp20-python", gimp.locale_directory)
)

main()



[ 2.8 is currently limited in recursions of groups inside groups. ]

Search tags:
gimp export layer positions, export positions of layers in gim, gimp layer position dumper plugin.

Tuesday, December 27, 2011

Use android device to connect to internet on PC using USB cable or any wireless source.

I was new to android, and wanted to connect to internet via GPRS/EDGE/3G connections. But unfortunately I couldn't find any modem support in android. In run of demand for a DUN connection I found tethering option in Android phone and found connecting to PC for internet via Android is dead easy!, thanks to tethering, below are the steps and references:-


My devices and setup:
Android version: v2.2, Froyo
Device: ZTE Blade (Or Dell XCD35, Idea Blade in India)
PC: Toshiba Satellite C650 AMD Athlon II P320 CPU, HD4200 ATI card
OS: Windows XP

STEPS:
1. Enable Internet on your Android phone via any source you have access to like GPRS/EDGE/3G data plans.
2. Connect the phone to your Laptop/desktop using USB cable (Otherwise below option will be disabled)
3. Go to phone settings and enable USB tethering :-

Press Home -> press menu -> wireless & networks -> Tethering & portable hotspot -> USB Tethering
Enable this check button.


Once enabled,  If your pc drivers are installed correctly, you will see HSUSB device connected message, remote NDIS adapter device will be shown on your device manager.


Verify the correct setup:
1. Check if your Android device shows BLUE USB icon on the taskbar which opens tethering upon touch event.
2. Open Device manager in windows XP or other OS. Network adapters should show

"Remote NDIS based internet sharing device"


My details are:
Manufacturer: ZTE Corporation
Location: Location 0 (ZTE HSUSB Device)
Control panel => Network Connections => Remote NDIS based internet sharing device




 4. Test internet on your phone if it works, then for sure you will get same speed in your PC.



You can test the speed of your internet by simple command. Open cmd.exe from run dialog and type

ping google.com

below is output from my console:

Pinging google.com [74.125.113.104] with 32 bytes of data:


Reply from 74.125.113.104: bytes=32 time=516ms TTL=45
Reply from 74.125.113.104: bytes=32 time=517ms TTL=45
Reply from 74.125.113.104: bytes=32 time=513ms TTL=45
Reply from 74.125.113.104: bytes=32 time=515ms TTL=45



The lower your time is the faster your internet connection will be. EDGE normally shows values between 200 to 700. Values above it are very slow connection. I get ~250 average in low traffic, ~20-30KBps.




CONCLUSION:
Android's USB tethering just means to share internet from your device to other device no matter what the source of your internet is. So we don't need any kind of Dial Up networking support in phones. So this is a universal solution and that's why android don't need DUN :-).




References:
Tethering & Hotspot
http://support.google.com/mobile/bin/answer.py?hl=en&answer=182134


Share your mobile data connection:
http://support.google.com/mobile/bin/answer.py?hl=en&answer=168932


Windows XP's Android RNDIS device information, tethering, INF file
http://www.android.com/drivers/tetherxp.inf



ZTE Blade drivers:
http://www.zte.co.jp/products/handsets/handsets_gallery/softbank/info/201012/P020101217594818380622.zip

ftp://ca:welcome@ftp.brightpointuk.co.uk/Technical%20Support/ZTE/ZTE_Handset_USB_Driver.exe


Plugging Android phone to PC shows a CDROM with their drivers which upon enabling SDCARD gets removed.



EXTRA (part of my marketing):

If above steps have solved your problem and you are happy, and you do not hate games :), please try the games I have developed.


DesiBallGame - My first android game, recently released

https://play.google.com/store/apps/details?id=org.greh.desiballgame


 My PlayStore profile:

https://play.google.com/store/apps/developer?id=GamesGreh


My website for games:

http://www.gamesgreh.in