Post Reply 

Help Creating a Script?

Oct 30, 2013, 08:32
Post: #1
Help Creating a Script?
So I have this project I'm doing in Gimp but it's very tedious. I'm thinking that I might be able to write a script to do it for me but I'm not sure. So I'm gonna explain the steps that I do and you guys can tell me if it can be done as a script.

So I take an image and I copy it to the clip board and then I change the image to grayscale and then back to rgb in order to remove the color from the layer (I know I can just desaturate but I prefer that method.). Then I paste in the copy so I have the grayscale layer on top and the original color layer on the bottom. and last I add an alpha channel to the grayscale layer.

Now here comes the tedious part. What I do is. I select the grayscale layer then make a selection that is the height of the image (Or the width depending on if the image is portrait or landscape and what I want) and about 75 pixels wide again depending on what I want the exact specifications to be. Starting and one end of the image. then I clear that selection so you see the color underneath. Then I flatten the image and save it as say Image 001.jpg. Then I undo the flatten and the clear and I move the selection over 1 pixel or 10 or however smooth I want to make the animation I redo the clear and the flatten and resave it again as Image 002.jpg. Doing this until I've gone across the entire image. Now if say the image was 2000 pixels wide then I would have to do 2000 images. See how that could be insane? So I was wondering if I could write a script to do that last part for me (the tedious select, clear, flatten, and then save over and over again) for me. Now I like to think I'm at least half smart about Gimp but if the way I'm doing it sounds crazy and insane and you guys can think of a better way then by all means let me know.


Thanks for any help anybody can give.
Find all posts by this user
Quote this message in a reply
Oct 30, 2013, 09:15
Post: #2
RE: Help Creating a Script?
In a script (and even manually) I would do it a bit diffferently:
  • Load image
  • Duplicate layer
  • Convert top to B&W (Colors/Desaturate is best)
  • Then loop:
    • Make color layer active
    • Select strip
    • Copy
    • Make B&W layer active
    • Paste
    • Save image to file
    • Delete pasted layer

Not very hard to do for someone who knows Scheme or Python.

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Oct 30, 2013, 09:36
Post: #3
RE: Help Creating a Script?
Thanks for the advice sadly I don't know Scheme or Python. I know Gimp but not much into the area of Scripts.
Find all posts by this user
Quote this message in a reply
Oct 30, 2013, 10:07
Post: #4
RE: Help Creating a Script?
Python isn't difficult if you already know how to program.

Otherwise I can give it a shot (long and rainy wek-end ahead). Some questions
- when the scan reaches top/bottom should it become gradually thinner or should it stop as soon as the edge of the "scan" reaches the edge of the canvas?
- should it wrap around (ie, at some point part of the scan appears at the bottom and the rest appears at the top)?
- should it have smooth edges?

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Oct 30, 2013, 19:24
Post: #5
RE: Help Creating a Script?
The scan should stay the same width and wrap around so it meets up with the first image so it looks like a continuous loop of sorts. I wanna be able to like select weather or not the image is landscape or portrait so that way the shortest side is the "fixed" length and I can enter a width for the scan. Like say if the image is 3000x2000 then it would automatically set the height to 2000 (the shorter side) and then I can input the width to say 75 or 5o or whatever and then it will just do its thing saving each image.
Find all posts by this user
Quote this message in a reply
Oct 30, 2013, 20:17 (This post was last modified: Oct 30, 2013 20:17 by ofnuts.)
Post: #6
RE: Help Creating a Script?
IMHO it's much more workable to tell if you want a vertical or horizontal scan. So that would be 5 parameters to generate the images:
  • The layer which is the "fixed" background (implicitly taken as the active layer when you start)
  • The layer from which the "strip" is extracted (the script expects you to have created it beforehand)
  • The scan direction
  • The strip width or height
  • The stepping (it will complain if the stepping isn't an exact divisor of the total width/height)

There are also additional parameters for the output files:
  • Target Directory
  • Root file name/Numbering scheme/File type.

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Oct 30, 2013, 22:38
Post: #7
RE: Help Creating a Script?
Yeah that makes more sense. Like I said I'm not really a programmer.
Find all posts by this user
Quote this message in a reply
Nov 1, 2013, 18:04
Post: #8
RE: Help Creating a Script?
Even simpler than I thought:

The script scanning-images-0.0.py is here

A sample of what you can do wit it is here (animated GIF produced with 80 images from the script, 8MB).

The script shouldn't be too hard to figure out, it expects:

- a layer with the "scanned" image (it doesn't appear in the dialog, it is the active layer when you start the script)
- a layer from which the scanning effect is extracted (specified in the dialog)
- a step size (which should be a divisor of the proper image dimension)(specified in the dialog)
- a scanning direction (specified in the dialog)
- a target directory for the files (specified in the dialog)
- a template to name the files (specified in the dialog)(the "%03d" in the default name means stick the picture number here, formatted to 3 digits padded with 0's). The files are saved with the given extension, using the default settings for that file type.
- a selection on the image: create the selection before calling the script. This selection is moved around to do the copy/paste from the "scanning effect" layer to the output layer, so you can use fancy selections (feather selection, rounded rectangle, or ellipse selection as in my demo image above).

The menu entry for the script should appear towards the bottom of "Filters".

Have fun

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Nov 2, 2013, 03:56 (This post was last modified: Nov 2, 2013 04:31 by Captain_Cereal_Hands.)
Post: #9
RE: Help Creating a Script?
Thank you very much I will give it a go.

Your a genius it works perfectly. Quick question I know that Gimp can do animation cause I've done it before but do you think it could handle 2,000 images? I wouldn't set the individual duration for very long.
Find all posts by this user
Quote this message in a reply
Nov 2, 2013, 09:19
Post: #10
RE: Help Creating a Script?
(Nov 2, 2013 03:56)Captain_Cereal_Hands Wrote:  ...Quick question I know that Gimp can do animation cause I've done it before but do you think it could handle 2,000 images? I wouldn't set the individual duration for very long.

Here's my 2 cents

You could be a bug tester and report back to us your results if you want to try it.

*BUT, 2,000 pictures might be alot to process, so if it did work, it coud be slow.
No doubt the file size would be huuuge, regardless of the hieght x width of the images unless its maybe a thumbnail or less in size.


*
Before you start,
tweaking these factors might yield favorable results:
- What is your purpose for a large animation such as this? (stick figure animations are nice, I've seen some long ones, very simple animations)
- If its for a long tutorials, people will recommend you use a screen capture software
-Can you combine any of the 2,000 images to make the animation shorter? (dispose duplicates)
- Dont go crazy big with the dimensions of the images for the gif, anything around 320 x 120 might be good.
------------
Only other thing I can think of is if it would be possible to import 2,000 images to begin with or would gimp crash :\ hmmm, looking forward to your findings keep us posted Smile !

"In order to succeed, your desire for success should be greater than fear of failure." BC
[Image: 29uocaf.png]
iFS007 tut vids on YT ~ auto color B&W landscape tut
Visit this user's website Find all posts by this user
Quote this message in a reply
Nov 2, 2013, 09:40 (This post was last modified: Nov 2, 2013 11:48 by ofnuts.)
Post: #11
RE: Help Creating a Script?
(Nov 2, 2013 03:56)Captain_Cereal_Hands Wrote:  Thank you very much I will give it a go.

Your a genius it works perfectly. Quick question I know that Gimp can do animation cause I've done it before but do you think it could handle 2,000 images? I wouldn't set the individual duration for very long.
Not a problem of duration but a problem of cumulative memory for all images. Plus the animated GIF format isn't very efficient so you'll end up with a huge file will all the problems this will create downstream (upload time, network bandwidth for site, memory/CPU usage in the users browsers, etc....)

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Nov 2, 2013, 10:15
Post: #12
RE: Help Creating a Script?
That is a nice little script from ofnuts, the effect is a little like a 'video wipe' without going from one image to another.

If you have problems with that large number of layers and Gimp then maybe try ImageMagick

Save the rendered png's to their own folder, working from that folder the basic IM command is

Code:
convert -delay 50 -loop 0 *.png ani.gif

That produces a big file so a slight modification to the command is

Code:
convert -delay 50 -loop 0 *.png -layers Optimize ani.gif

much smaller but can produce unexpected results depending on the images.

best of luck

** https://www.gimp-forum.net/ now answering questions**
Find all posts by this user
Quote this message in a reply
Nov 2, 2013, 20:50
Post: #13
RE: Help Creating a Script?
First of all I don't know if I'll get to testing the animation cause the plugin keeps crashing during the scan. I load the image and do the 2 layers then I go to the plugin and I select horizontal scan and then I set the increment to 1 pixel which concidering the image is 2,000 pixels wide should generate 2,000 images. Also I change the file extension to .jpg cause .png generates pictures that are 5Mb's each and jpg's are only like 600Kb's each. So I hit go and it always crashes at random points during the scan so idk...
Find all posts by this user
Quote this message in a reply
Nov 2, 2013, 21:04
Post: #14
RE: Help Creating a Script?
Well, given your numbers it will generate over 1GB of data, so checking for enough disk space is a good idea. After that you may hit a memory usage problem; can you watch the status bar at the bottom of the image and see if the indicated memory grows beyond limits?

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Nov 2, 2013, 21:18
Post: #15
RE: Help Creating a Script?
Hmm. Definitely a memory usage bug due to the undo stack. Disabled undo and now the memory usage remains stable. Download version 0.1 from the same place and give it a try.

Now answering your questions on
https://Gimp-Forum.net
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Request for script chlebna 1 171 Sep 13, 2017 09:35
Last Post: ythgilb
  Request for script - Guillotine + Watermark sunslick 1 229 Sep 4, 2017 08:51
Last Post: ythgilb
  Script-fu: How to create new, addressable layer using gimp-floating-sel-to-layer Bertholom√§us 2 230 Aug 31, 2017 14:32
Last Post: Bertholomäus
  How to modify this script-fu? Zakary81 1 195 Aug 23, 2017 12:48
Last Post: paynekj
  creating multiple sized images from one ntuck86 1 198 Jul 29, 2017 08:18
Last Post: ythgilb

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS