Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My first python plugin review
#11
I've updated the code to handle pretty much any aspect ratio, and I added some standard aspect ratios as defaults.

https://github.com/origamifreak2/Gimp-Pl...t_ratio.py

I actually took a look at one of your plugins @Ofnuts to see how to register multiple plugins under the same submenu. Let me know if there's anything I can improve  Smile
Reply
#12
(01-01-2025, 12:39 AM)origamifreak2 Wrote: Thanks Ofnuts  Smile  . I updated my code. I also added some logic to convert the image to RGB mode if it's indexed.

This isn't something I would do. I would only enable the filter on RGB* and GRAYSCALE*. Then if someone really wants to use the filter on an indexed image, de-indexing it beforehand  is a quick single-click away. Because now your filter needs to re-index the image, and how to do so properly is a nice can of worms (how many colors? which palette?).
Reply
#13
Thanks again Ofnuts

I took your suggestion. I've also made a ton of other changes to the code.
  • added ability to fill background with the active foreground color
  • added ability to fill background with the active background color
  • added ability to fill background with a different user selected color
  • added ability to fill background with transparency
  • added ability for user to select a specific blur radius between 0 and 500
The code is quite a bit more complicated now, but please feel free to take a look and let me know if anything could be done better.
Reply
#14
elif(background_type == 1 or background_type == 2 or background_type == 3) better written as if background_type in [1,2,3]

elif(background_type == 4): # transparent background
# do nothing since resized canvas background is already transparent
pass


better written as
else: # transparent background case: do nothing since resized canvas background is already transparent
pass

(always better to have an explicit else to catch what we could have forgotten)

Instead of saving the color, you can bracket your code with gimp.context_push()/gimp.context_pop() (like the undo group), so that any context change you make for the script is reset when the script exits.

Blur radius can be a PF_SLIDER, easier for the user and since you add value boundaries you naturally limit the user to what Gimp's blur allows.

When you use pre-defined values as parameters, use their name, for instance pdb.gimp_image_merge_down(image, drawable, 1) is better written pdb.gimp_image_merge_down(image, drawable,CLIP_TO_IMAGE ) (note the "-/_" substitution).
Reply


Forum Jump: