Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

270 subsequent JPG files of a turned needle in a dial

Fri Dec 08, 2017 3:41 pm

I need to make 270 subsequent JPG files of a needle in a dial (I have to upload this to a TFT screen)
the basic idea is draw the needle and the automatically turn and save the file (needle001, needle002.jpg etc.)
Try to change the script-fu-copy-rotate script. But this keeps on creating new layers and not discarding the old.
(let alone the problem of saving it to the next number)

Am I doing this in the right way or should I do something else and maybe simpler...


define (script-fu-copy-rotate-nLayer inImage inLayer xCenter yCenter StartAngle Objects)
(let* ( (drawable 0)
(rAngle 0)
(BoxWidth 0) (BoxHeight 0)
(xoffset 0) (yoffset 0)
(countdown 0)
(sel-float 0)
(degree 0)
(imageWidth (car (gimp-image-width inImage)))
)
(set! BoxWidth (cadr (gimp-selection-bounds inImage)))
(set! BoxHeight (caddr (gimp-selection-bounds inImage)))
(set! countdown 0)
(set! xoffset BoxWidth)
(set! yoffset BoxHeight)
(set! drawable inLayer)
(set! rAngle (* StartAngle (/ 3.14159 180)))
(gimp-layer-resize-to-image-size inLayer)
(gimp-edit-copy drawable);copy
(gimp-edit-clear drawable);clear selection to handle partial transparency

(while (< countdown Objects)
(begin
(set! degree (* rAngle countdown))
(set! sel-float (car (gimp-edit-paste drawable FALSE)));paste
(gimp-item-transform-rotate sel-float degree FALSE xCenter xCenter)
;
; (gimp-layer-set-offsets sel-float xoffset yoffset);move
; (gimp-drawable-transform-rotate-default sel-float degree FALSE xCenter xCenter FALSE FALSE);rotate
; (gimp-floating-sel-to-layer sel-float);make each transform a new layer
; (gimp-floating-sel-remove sel-float)
; (gimp-floating-sel-anchor sel-float);anchor each transform to start layer
(set! countdown (+ countdown 1))
);begin
);while
(gimp-displays-flush)
);let
) ;;def



(script-fu-register
"script-fu-copy-rotate-nLayer"
_"<Image>/_Select/_script-fu-copy-rotate-nLayer"
"copy active selection rotate and anchor it to a new layer "
"*"
"*"
"01/13/2010"
"RGB* GRAY* INDEXED*"
SF-IMAGE "The Image" 0
SF-DRAWABLE "The Layer" 0
SF-ADJUSTMENT "Center (x-coordinate)" '(200 0 9999 1 10 0 1)
SF-ADJUSTMENT "Center (y-coordinate)" '(200 0 9999 1 10 0 1)
SF-ADJUSTMENT "Angle" '(120 -360 360 0.1 1 1 1)
SF-ADJUSTMENT "Number of Objects" '(1 -9999 9999 1 10 0 1)
)

Re: 270 subsequent JPG files of a turned needle in a dial

Fri Dec 08, 2017 5:43 pm

It looks like you are making an animation. When you playback the frames (filters>animation>playback) you may need to add the tag 'replace' on the layers (frames).

Good on you for writing a script for this task. I usually import a video into Gimp using gimp-gap, convert it to frames, make animation and then export as an AVI. From there I make it into a GIF or even better a WEBM animation.

BTW, 'WELCOME'.
Image

Re: 270 subsequent JPG files of a turned needle in a dial

Sat Dec 09, 2017 6:23 am

Thank you

no I am not making an animation. I want to make JPGs for a TFT screen. Every position of the needle has to be a JPG file. So I need to make 1 degree turns and then 270 times.
quite laborious.

I borrowed the scheme but it makes a new script over and over. I just want a turn and a save to a new file

with some advise I can do that

thanks

Re: 270 subsequent JPG files of a turned needle in a dial

Sat Dec 09, 2017 7:04 am

Hi willemg12,
The dial stays the same when it has no needle and only the angle of the needle changes but it must have a transparent background
or alpha channel.
You have a common background (dial) layer that you duplicate and use as a guide to position the needle at the maximum or minimum position. Then you delete the background so you just have the needle.
Then I would use G'Mic-Qt > Testing > Garage Coder > Smart Rotate. You need to advance the needle 1 degree, duplicate the layer and advance the needle 1 degree again, 270 times. That filter can give 360 degrees at 1 degree increments. A bit more than you need.
Finally you need to combine the background with the 270 needle layers. It would work. :jumpclap

Re: 270 subsequent JPG files of a turned needle in a dial

Sat Dec 09, 2017 7:05 am

You need more than one script/plugin

With background and pointer layers copy-rotate-n-layers

screenshot https://i.imgur.com/xSXW2xf.jpg

You can use a plugin to merge the background with the generated layers. This one Ofnuts of-interleave-layers-0.4.py in sprite mode. See towards the bottom of here: https://sourceforge.net/projects/gimp-t ... s/scripts/

https://i.imgur.com/tt2ytCM.jpg

Then a script to export all the layers to separate numbered files. I use this plugin anitools.py http://registry.gimp.org/node/25029 but that generates png's only

https://i.imgur.com/vr4P25h.jpg

There are other scripts/plugins that do the same thing.

Re: 270 subsequent JPG files of a turned needle in a dial

Sat Dec 09, 2017 9:06 am

Here's my solution for this job:

Open/create the needle.

1. Clone-Layer-Tool 0.2b, has more options and up to 1000 layer copies. Make sure additional options has Lanczos3 interpolation and "each clone to layer" ticked.
Otherwise they'll be in a group and you need to unpack it. But rotate nLayer handles this step as well I guess.
2. Place your dial image on the bottom, make sure all layers are visible. Run "Combine background" by Saulgoode. Delete the empty dial layer from bottom.
3. "Save all layers script", also by SaulGoode. I have modified line 90 in the script, so that it creates files with 3 numbers, use Needle.jpg in the name template field and they'll be saved as Needle001.jpg to Needle271.jpg.

Attached the plugin and scripts.
Clone layer Tool in Layer menu, Combine background in Animators menu and save all layers in File menu.

Re: 270 subsequent JPG files of a turned needle in a dial

Sat Dec 09, 2017 12:08 pm

I think GAP could be a good way of going about it because what you can do is use the "Filter All Layers" option..
Download GAP from GAP ...<< Link (check the top right of webpage)).
Extract the files, navigate to the folder entitled 'GAP-installer', open and click on the executable file, go through clicking on language settings etc.. then at the 'Choose Install Location' part, choose your Desktop. Extract and you'll have 2 folder "lib" and "share", open the lib folder find all the plug-ins and copy them, find your Gimp User folder (i.e. User/../.gimp-2.8 folder) paste or drop those files into your plug-ins folder.. also there are a couple of scripts in the 'share' folder you downloaded with GAP, put those in your .gimp-2.8 scripts folder.. done) Start / Re-start GIMP

I would draw the needle, centred (using guides), on a transparent background , the needle can point to 12 o' clock for this example, THEN.. duplicate that layer so that you end up with 270 identical layers (it's a lot of clicking but you could do say 20 or so then use a "Mirror layers" plug-in (included below) & Ctrl+F a few times or so..), after that go to Filters > Filter All Layers, scroll down near the bottom of the list to "plug-in-wr-layer-rotate-any" and click on "Apply Varying" then in that dialog box you could set the first value to -135 degrees (as an example) click OK, then click Continue, set the second value at 135 degrees (just delete the minus symbol..), then click Continue again and the plug -in will do it's thing rotating each needle from -135 to +135 degrees.
So when that finishes create a new layer at the bottom of your Layers stack and draw the background dial so that it fits in with where the needle goes, use the Combine script (below), 'Filters > Animation > Combine with background' and when that finishes don't forget to delete the first layer. save and then to create the jpeg's simply click on the "Video" drop-down menu and go to "Split Image to Frames", remembering to change the extension to ".jpg" in the Split Settings dialog, OK that and OK the jpg quality settings (should be adequate as they are) and.. hey presto - 270 jpg's will be created.

Mirror Layers:
mirror-layers-0.1.zip

Combine background:
sg-combine-bg.scm

Gregs Crosshairs.scm

Re: 270 subsequent JPG files of a turned needle in a dial

Sun Dec 10, 2017 11:16 am

That was entertaining and adventurous.
Learning point number one: there seems always to be a script for it... (dont do it yourself)

I picked a bit of Rich and a bot of NidHogg. And it worked (most important)

I could nog get the file saving from anitool running (still looking where that went, any help on that is greatly appreciated) but the file save from Saulgood worked just well, so then I had it all it was done in a jiff.

The conversion from PNG to JPG was easy: imagebatch a free tool does it in a second

(the only thing to do now is make the proper background (Volts and Amps designators and we are good to go).
PS: I am programming a Nextion TFT touch screen display for a lab supply.

Re: 270 subsequent JPG files of a turned needle in a dial

Sun Dec 10, 2017 12:25 pm

Don't want to rain on your parade, but since there is shadow effect on the needle, you can't just rotate it...

Re: 270 subsequent JPG files of a turned needle in a dial

Sun Dec 10, 2017 4:07 pm

Don't wanna' rain on your parade either, but if you had just used a video editor / compositor, you'd have had this done a long time ago. You can always export to image sequence in .jpg format or use a converter.

Image

Re: 270 subsequent JPG files of a turned needle in a dial

Sun Dec 10, 2017 4:15 pm

Agreed with Ofnuts, you should not use shadow with this method.
Conversion from png to jpg was unnecessary. You can save straight to .jpg, and probably many more formats with SaulGoode "save all layers".
The script in my download, like I mentioned was edited to make the filename suffix 3-numerical instead of 4.

racer-x, you're living too fast :hehe

Re: 270 subsequent JPG files of a turned needle in a dial

Sat Dec 23, 2017 11:52 am

racer-x wrote:Don't wanna' rain on your parade either, but if you had just used a video editor / compositor, you'd have had this done a long time ago. You can always export to image sequence in .jpg format or use a converter.


Alternately, this would be a great task for POVRay, as it supports animation variables out of the box - probably a 20 line job to render a photorealistic needle and create the 270 images....

-Rob A>
Post a reply