Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My first python plugin review
#2
Quite decent. To nitpick a bit:
  • Starting names with underscores in Python has a special meaning, so no point in using _image and _drawable instead of image and drawable
  • forground is spelled foreground
  • speaking of foreground, it would be more proper IMHO to make a copy to use it as the image background
  • the  drawable that you get as an argument could be a group, a layer mask, or a channel, you should probably bail out with a message for the last two. The group would be doable (the copy() makes a complete duplicate of the group, and you can flatten one of the two groups to blur the result).
  • you can get the width and height of the image using the attributes of the image object: image.width, image.height, which is more readable than calling the PDB.
  • In Python v2, an operation between int and float produces a float, so you can drop several uses of float() by using float constants: float(canvas_height) / 9 is also canvas_height/9.
  • your if/elif has no else... which happens when the image is already 16/9 (*).
  • lots of  common code between the two if/elif blocks. Some of it could be taken out. Personally, I would just set the new canvas/width or height. Then outside of the conditions the code would take care of offsets and such. Yes, the computations would yield  0 for one of the values...
  • And when you do the above, you can remove the if/elif, because you can write: canvas_width = max(width_16_9,canvas_width) and same for height. And your code miraculously behaves if the image is already 16/9.
  • I don't see the purpose of computing bg_scale, since anyway the background will be sized to the new  canvas dimensions that you already have.
  • your blur radius could be dependent on the image size: a 90 blur isn't the same on a 200x200 image and a 2000x2000 image.
  • you should bracket all your code except initial checks between image.undo_group_start()/image.undo_group_end() so that the whole effect of the script can be undone with a single Ctrl-Z.
15/20.

"Perfection isn't when there is nothing to add, but when there is nothing left to remove."
Antoine de Saint-Exupery 

(*) if statements are useful but dangerous, because they are a major source of bugs. Trying to avoid them is the best way to understand what is going on in your code.
Reply


Messages In This Thread
My first python plugin review - by origamifreak2 - 12-28-2024, 02:59 AM
RE: My first python plugin review - by Ofnuts - 12-28-2024, 09:08 AM
RE: My first python plugin review - by Ofnuts - 12-29-2024, 09:18 AM
RE: My first python plugin review - by gasMask - 12-29-2024, 12:22 AM
RE: My first python plugin review - by Ofnuts - 12-31-2024, 09:56 PM
RE: My first python plugin review - by Ofnuts - 01-01-2025, 09:26 AM
RE: My first python plugin review - by Ofnuts - 01-06-2025, 09:03 AM
RE: My first python plugin review - by Ofnuts - Yesterday, 09:18 AM

Forum Jump: