It is currently Mon Sep 14, 2026 5:29 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Does anyone know Node.js syntax for use w/ a GIMP script ..[SOLVED]
PostPosted: Thu Jul 06, 2017 10:31 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jan 06, 2017
Posts: 204
I need to write some code to rename files, image files to use with the "build map" python script, I know there are some renaming type programs out there, in fact I was using Irfan View, but there's only so far you can go i.e. if I divided a large picture into 100 squares on a 10 x 10 grid, named the first lot of files 1x0.bmp, 2x0.bmp,... 10x0.bmp, then 2x0.bmp, 2x1.bmp,.. etc etc up to 10x10.bmp then i can use the build map script to put all those pieces back together to form one whole picture (or as I did before use it to make images of coloured blocks (see viewtopic.php?f=9&t=15480&hilit=Build+Map&start=10#p214417))
Anyway renaming with Irfan View means I can name the first lot by putting in the Batch rename settings (Pattern setting) something like: 0x# (and it's specified in the settings to increment by 1 each time) so it will then remane the folders 0x1.bmp, 0x2.bmp etc but I can't get it to rename multiple strings (or even 2) in the same filename.
I turned to a free utility called BRU (http://www.bulkrenameutility.co.uk/Main_Intro.php) which i find out can do it only (apparently) by using the JavaScript section of the UI, unfortunately you have to register as a commercial user and buy a license for 90 odd dollars.. so .. I know that from within the BRU program it's possible to highlight the files , and place the code in to get the desired result, the code being:
    newName = (~~(counter / 10)+1) + "x" + counter % 10;


However, now I have Node.js and this snippet of code BUT, I have no idea how to write the rest of the code to link the File path so the program knows where they are and to implement the renaming code to this particular path (i.e. "C:\Program Files/Project/pics" ..or some such)
Sorry for the long-winded explanation and request but hopefully someone out there will be willing to torture themselves... ahem I mean, help me out with this (it might even spur me on to learn a bit more about programming..!!) Thanks :)


Last edited by Zero01 on Thu Jul 06, 2017 3:23 pm, edited 1 time in total.

Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Does anyone know Node.js syntax for use w/ a GIMP script (sort of.
PostPosted: Thu Jul 06, 2017 2:25 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
Why don't you do it in Python?

import glob,os

for i,oldname in enumerate(glob.glob('*.png')):
    newname='%02dx%02d.png' % (1+(i/10),1+(i%10))
    os.rename(oldname, newname)

_________________
Image


Top
 Post subject: Re: Does anyone know Node.js syntax for use w/ a GIMP script (sort of.
PostPosted: Thu Jul 06, 2017 3:21 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: Jan 06, 2017
Posts: 204
That worked a treat!

Now i need to learn Python I suppose :lol

:coolthup :tyspin

EDIT: In fact, I had to modify part of your code: changed "newname='%02dx%02d..." to "newname='%01dx%01d..."etc, only because the Build map plug-in was expecting the first image to be literally '1x1.bmp' - my mistake for giving the wrong description, but still... good stuff, cheers!


Top
 Post subject: Re: Does anyone know Node.js syntax for use w/ a GIMP script (sort of.
PostPosted: Thu Jul 06, 2017 4:47 pm  (#4) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
Zero01 wrote:
Now i need to learn Python I suppose :lol


Why "now"? You should learn Python, period. Python is the road to freedom and cool Gimp scripts.

_________________
Image


Top
 Post subject: Re: Does anyone know Node.js syntax for use w/ a GIMP script ..[SOLVED
PostPosted: Fri Jul 07, 2017 5:22 am  (#5) 
Offline
GimpChat Member
User avatar

Joined: Jan 06, 2017
Posts: 204
Me, learn something, with my reputation...? :faint

:coolthup :hehe


Top
 Post subject: Re: Does anyone know Node.js syntax for use w/ a GIMP script ..[SOLVED
PostPosted: Sat Jul 08, 2017 3:19 pm  (#6) 
Offline
GimpChat Member
User avatar

Joined: Jan 06, 2017
Posts: 204
Just out of interest, would you happen to know of any good tutorial videos or any information (not necessarily about Python itself).. maybe something that goes over the concepts involved, algorithms etc etc.. just asking as you seem to know what you're doing!
I'm just someone who has little knowledge but a fair bit of interest and resolve to get into it?

https://xkcd.com/353/

Cheers.


Top
 Post subject: Re: Does anyone know Node.js syntax for use w/ a GIMP script ..[SOLVED
PostPosted: Sat Jul 08, 2017 3:35 pm  (#7) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4812
I've been told a lot of good about this/ But I never used it, when I took on Python it was my 25th programming language :)

Also, lots of good people and answers here.

Welcome to the flying tribe....

_________________
Image


Top
 Post subject: Re: Does anyone know Node.js syntax for use w/ a GIMP script ..[SOLVED
PostPosted: Sat Jul 08, 2017 3:47 pm  (#8) 
Offline
GimpChat Member
User avatar

Joined: Jan 06, 2017
Posts: 204
Thanks ofnuts, appreciate it :)


Top
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]



* Login  



Powered by phpBB3 © phpBB Group