Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Transform an image into different aspect ratios
#2

  1. Try image.filename. Then (with an import os), os.path.basename(image.filename) and may be even os.path.splitext(os.path.basename(image.filename))[0] if you want to drop the extension
  2. A "drawable" is anything you can paint on: layer, layer mask or channel, usually a layer. If you save the image as JPEG, no point in adding a white layer, Gimp will do it for you (if the background color is set to white of course). And if you add a layer, you have to merge the layers or create a new-from-visible to pass to the save call.
  3. You can't undo in a a script. In a script you know what you are doing and you don't need to undo (undoing is meant for the puny humans). The APIs with *undo* are there to 1) allow you to be nice to the user (undo_group_start/end) or 2) improve performance (undo_freeze/thaw and undo_disable/enable). 
For this kind of process you do something like this:
  • create a new image with the target dimensions (this "behind the scenes" image has no "view", you won't see it on the screen).
  • disable undo in that image (makes the rest run faster)
  • create a new-from-visible in the source image using the new image as the destination
  • insert that layer in the new image
  • resize the layer and apply offsets
  • save the layer (note that for this you have to work from the filename of the source image of course)
  • delete the new image (gimp.delete(new_image))
  • repeat for another set of dimensions
      
A very overlooked dialog is the Images dialog because it shows all images, even those without an attached view, so allows you to still see the images create by your script, and lets you
create a view on them if you want to check out things:

   

And of course when your script ends you shouldn't see any lingering image there.
Reply


Messages In This Thread
RE: Transform an image into different aspect ratios - by Ofnuts - 01-18-2024, 11:14 PM

Forum Jump: