GIF frames deleting script. - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP) +---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions) +---- Thread: GIF frames deleting script. (/Thread-GIF-frames-deleting-script) |
GIF frames deleting script. - rey - 04-02-2023 I understand it's not polite to bluntly ask for anybody to make a script that i need, so hope asomebody can give hints on commands i must use to try to achieve my goal. The goal is a a script that makes automatic deletion of GIF frames(layers) based on 2 parameters, and then exports file in original location adding some "copy"/"-01" to name. The deletion logic should work like "delete X frames after each Y frames". For example: = GIF with 22 frames, parameters are X=2 Y=3, after processing there will be: 1 2 = GIF with 22 frames, parameters are X=1 Y=4, after processing there will be: 1 [ Hope for your help. RE: GIF frames deleting script. - rey - 04-03-2023 I've got this script as start: Code: image = gimp.image_list()[0] but it only does like 30% of goal. RE: GIF frames deleting script. - Ofnuts - 04-03-2023 Pretty close. Something like this: 1. Depends if you work top down of bottom up Code: layers=image.layers[:] # Make a copy of the list 2. Select layers Code: keep=3 At that point you can inspect the contents of delete_layers to make sure they are the ones 3. Delete them Code: for l in deleted_layers: Coded in slo-mo (so to speak) for better readability, a tattooed Python coder would have done a one-liner RE: GIF frames deleting script. - rey - 04-03-2023 @Ofnuts thank you for code. Py scripts need some special variable setting?(data type or smth) Code: Error: eval: unbound variable: layers=image.layers[:] RE: GIF frames deleting script. - Ofnuts - 04-03-2023 (04-03-2023, 05:18 PM)rey Wrote: @Ofnuts thank you for code. Py scripts need some special variable setting?(data type or smth) No, but it needs your image = gimp.image_list()[0] first :-) RE: GIF frames deleting script. - teapot - 04-04-2023 Hi Ofnuts, I'm confused by this line of your suggested code: (04-03-2023, 02:41 PM)Ofnuts Wrote: I get that it makes a copy of a list but could it just be: Code: layers=image.layers I thought the ‘layers’ attribute of an image or layer group builds a new Python list and copies into it the IDs of the layers so that gives the plugin it's own private list anyway? RE: GIF frames deleting script. - Ofnuts - 04-04-2023 (04-04-2023, 03:30 AM)teapot Wrote: Hi Ofnuts, I'm confused by this line of your suggested code: Maybe, and maybe not. The indexation operator [] is just a call to a __getitem__() method, so image.layers could be live-wired into the image layers, retrieving layers on the fly when __getitem__() is called. In other words it's indexable but not necessarily a list. And in that case iterating the collection while deleting stuff in it is not going to be pretty. Of course, in this particular case, it is a list, so yes, the copy isn't entirely necessary. RE: GIF frames deleting script. - teapot - 04-05-2023 (04-04-2023, 07:26 AM)Ofnuts Wrote:(04-04-2023, 03:30 AM)teapot Wrote: Hi Ofnuts, I'm confused by this line of your suggested code: Thank you for your explanation. |