Writing GIMP Plugins with Python

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so how do you make a plugin it's not that complicated and right now i'm gonna teach you how to make a plugin and just for the sake of having some goal quote um we're going to make this plug-in just center center the visible layers of the um we're going to just center the visible layers of in the file that you have um just put them in the middle because you know at least we can then see some thing in the distance you know you can get some good idea um before even making the plug-in we need to to have open of course and go into preferences right here under edit the very bottom it says folders so we're just going to open up that and we're going to click on this plugins right here it says plugins um so after clicking this just select the first uh directory select all copy i'm just going to hit ok and close up we're just going to go into the file explorer paste the directory in and oh i didn't copy it correctly but thankfully i do have it pinned so if this is going to be different for you remember to copy it um the next thing you're going to do is just click create new text document and create something and i'm going to call it center dot pi make sure it's a python file yes this is in python um if you've never done python before don't worry it is it's kind of drawing the beginning but you know you get used to it i'm gonna uh open it you can open it and whatever if maybe you've done python before you have a proper editor but for the for the sake of this tutorial i'm just using visual studio so um let's begin with the file and i opened it up here and it's blank obviously now we need to populate it first let's just uh set up the python ability or whatever um with this line and i'm just going to type it out it's uh hashtag exclamation point slash user slash bin slash enb python 2 and i'm using the python 2 and i'm just going to import um the stuff with this line right here these are gonna be like the same throughout every plug-in so no need to worry um i'm just gonna put in a function right here and i'll explain what it does once i finish i'm just going to be called center elements it's going to take an image and um and this is just our dummy function and these are required elements so that the knows what it's trying to edit basically um and finally this is the important part this is your register uh the register is basically it's gonna tell all the information about your plugin that it ever would want to know so basically open up uh just something just type register and open up some parentheses and let's put the name of it center and next you put the blurb so center this is gonna appear when you open the window so it's gonna say center uh visible elements in the file we can we can change this to layers in the file and put a smaller description down here center elements uh put your name your copyright and the year i'm just gonna go ahead and put my name copyright and the year here as well um [Music] this is where you're gonna access it from um uh functionality i'm just gonna name the tab where you open it up from functionality and i'm just going to name it center elements and this is what the images you can use it on are so stars all next these are going to be the there's two sets of these square brackets and the function uh that it takes so basically i'm going to open up one of them because these are the these are the variables that you're gonna put in um and this is the function down here that it's gonna run which has to take as many variables plus these two as are in here so right now it has none if we open up actually we should get um under a functionality tab center elements so if we go in here we can't see it up here because we can't see it because we got to put main right here because you need to run the program that was an intentional oversight be right back all right we're back in um as you can see in functionality tab has center elements so if we create a new file we can click it there's absolutely nothing but that's okay because we haven't told it to do anything so it's doing exactly what we want it to do um so all right let's begin with understanding the system for variables so in the case of first in the case of our program we don't technically need any variables because it's just going to center stuff but for the sake of uh of the program let's just have a variable here called um it's gonna be let's let's make a boolean and we're just gonna call this dummy this is a dummy variable and 0 just defaulted to no or false but it displaces no in which is nice actually it looks user friendly and make sure to add the dummy up here as well so now it's just gonna have dummy inside of the box okay if we open up a new file and yes you do have to have a file open to run this stuff we hit center elements it's going to open up a box and as you can see it's just says dummy center visible layers in the file which is our description and right here we can just check check yes or no which will in the end of the day affect nothing but um if you do and this is important if you do want to input variables which a lot of plugins will input variables just add a variable here if you want to add another one just add a comma and remember to name this and put it in the list of variables that it inputs up here as well it's very simple very straightforward all right so in the case of our program we just want to center the variables so what i'm going to do is i'm going to go up here and i'm going to uh first create a function to grab all the visible layers in the um in the project now here's the thing uh this is the this is essential okay this is the python documentation link in the description please check it out um it explains a ton of stuff it gives you a ton of different functions out here but but even better is is super nice about giving us you know giving us a help and helping hand if you go under help and procedure browser it's going to open up this uh tab right here and this is every procedure in the program so you can find if it's here you know you can you can use it in your program um like move uh you can't move there's it's i think it's it's something else but you know it's gonna start with and then layer and then there's there's there's a bunch of functions for you to to use super useful look look here and then you can apply these to your program now let's i'm just gonna start writing out a function explain what it's doing um i'm just going to define a new function it's going to be called list list all visible and it's going to take a parent layer and a list output list and this is pretty basic um we're going to loop through for layer in parent dot layers so this is just gonna loop through every layer inside of the um parent this is gonna be your cursive function so it's gonna loop through all the layers in the parent and it's just gonna ask if and this is important pbd is a pdb my bad pdb is the uh it's like the big it holds all the functions so it holds all that stuff that i showed you and in this case it's layer get visible and you input the layer so this is our layer that's recursive so it's very that's that's the entire line basically is um it's just if the if if the layer is visible then obviously we're going to append um not list output list we're going to append the layer um and where the second thing we're going to do is because has group layers all right so this is the uh another thing is when you're making these remember that has groups especially when you're dealing with layers um and this is why this is recursive if we do if pdb.gimp item is group layer then we're just going to list all visible and we're going to just do it to the layer outputting the output list so basically it's going to go through every single layer in the entire project you can have as many groups inside of groups as you want and it's still going to do this and it's going to add every single visible layer to that list perfect so right now we have this nice function but we don't have functionality so i'm just gonna do this i'm gonna make a new uh array and i'm just gonna list all visible and the parent is going to be the image right and the uh layers are going to be the layers so it's just going to make this list into every uh it's going to a list it's an array my bad uh bad habit and it's gonna populate it with every layer in the entire project so then we can start doing stuff with this so for each layer in layers all we're going to do is we're just going to center it and that's pretty simple all we need to do is uh get this function called pdb dot layer set offsets and this takes a layer so we're gonna obviously take our layer and then it takes an x and a y that we need to input in um now if we think about it we don't need we don't need to worry about our y we only need to worry about our x because we're centering it so think about it this way we're going to take the image's width and width and divide it by two then we're gonna subtract half of the layers with um because if you think about it's all centered i think it's the pivot is the middle i'm pretty sure maybe it will break if you change the pivot but um i'm almost i'm 100 sure that this works as is now this is um this is it we're just taking the image's width and dividing by two to get the middle if we open up paint here i can kind of explain and i will spare your eyes and make this black so it's this is the file and just dividing it by two and it's putting our image in the middle right here because i think the origin is right here because the origin of the file is right here um and then it's just shifting it halfway so that it's centered um enough explanation let's finish this up by telling uh to just not mess with the layers y so layer dot offsets because it's not position or anything it's just uh i think it's a tuple at this position and it's the first element i mean the second element because it's one and that should be pretty much it um to just center everything so if we open up game and we create a new file i'm just going to go ahead and um you know something that's really annoying in is actually messing with text so i'm just going to put some text in here to center because uh center this you know we just want to center this oh man this is all the way over here um i want to center it so i'm going to click center elements and it's going to open up and we're just going to hit ok and it's going to center the element now this is you know oh wait how is this useful um actually it's very useful because if you have a bazillion different center this is you know it's going to take some time you know i kind of want to i kind of feel like i want to manually move these so you know and then you have to estimate oops this is actually a big mistake because i wasn't adding a new layer i was uh let's just create a few new layers and why not our background is skewed and messed up as well actually i'm just gonna keep the background regardless multiple elements we hit our uh okay and i will center everything wow very cool saving you a ton of time you know unbelievable now you may be thinking hey why do we have a dummy there what's so useful about the dummy so what we can actually do just really quick is say pf float um and remember you can find all the different things you can input in the description there's a link to the documentation just search up control fpf um a bit of tongue twister we're just gonna name it exposition so that we can have a i mean y position my bad we can have you know a bit of a a y position for the elements to be set so in here i'm going to take instead of dummy remember to replace it with y position so it's readable and stuff and in here we're just going to put y position and if we reopen because we remember you have to reload the entire program i'm going to go ahead and pause it and restart when it's done so as you can see i spent some time you know here's a layer right here of little dude there's the center of this text as well but here's what's special about our new program we're going to open up center elements and we're going to just put it it's y position and remember you can see down here the y position so let's just pick you know around 650 and if we hit ok it will put everything at 650. um and remember the top is what it sets it at so if you want to like make it the center just divide it by two um like we did before now you're like what why'd the background have to move like this isn't not cool so if we undo we can simply hide the background and we can do the same thing remember what's cool is actually saves your last preference so if we hit ok it's going to go down there and our background is in the exact same spot because of our features you can see this with a little dude if i copy this dude this little guy and um i'm gonna make him i feel like making him blue this blue guy doesn't want to move right he wants to stay right here we hide him hide the background open up our functionality click ok and neither our blue guy or our background moved and both of them are really ecstatic this guy is happy that he didn't get moved by the program that's pretty much it for plugins uh knock yourself out you know see here's the thing if you have the ability to create plug-ins for software then you know it's not the sky's the limit but sometimes it is the sky's the limit um i can show you an example of something complicated a plug-in that is fairly complex and basically this plug-in does an advanced version of what um i just taught you how to do and it has a ton more features and it works exclusively on text um just because i needed something so anyway this is just a show you know you can pick you can have color pickers in your in your little box um remember links in the description um your flash editor myself flash on the screen a dude little the little dude from the program saying links in the description look at the documentation it's so helpful it's very very helpful um you know it's harder to debuff here's the thing it's harder to debug in but um you find a way you will find a way i believe in you you can make a plug in anyway ladies and gentlemen i hope you successfully created your plugin and i hope you successfully create the plugin that you want to create have an excellent evening bye
Info
Channel: CodeGnat Studios
Views: 545
Rating: undefined out of 5
Keywords: python, gimp, plugin
Id: 8z0VEFBSgqA
Channel Id: undefined
Length: 22min 54sec (1374 seconds)
Published: Fri Jul 23 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.