Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GIMP - Scripting a canvas resize

Just started using GIMP today. When I resize the canvas manually in GIMP (so that it's smaller than the image size) it lets me move the image around so that I can "change" the viewable area. How do I replicate this in a script? In other words, I want the script to pause at the canvas resizing step and let me position the image correctly.

The reason I'm asking: I've written a small script that will create square thumbnails of images. The way I'm doing this is by resizing the canvas so that the height and width are the same. If the height and width are different I change the higher of the two so that it is the same as the lower (e.g. 600x500 becomes 500x500). I then flatten the image and scale it to whatever I need.

(if (>= width height)
    (begin
        (gimp-image-resize image height height 0 0)
    )
    (begin
        (gimp-image-resize image width width 0 0)
    )
)

The code I'm using to resize the canvas is above. I know the last two values in the gimp-image-resize command refer to the offsets. This is what I want to manually modify when the script reaches this step. Any help would be greatly appreciated. Thanks!

like image 634
zdyn Avatar asked Oct 07 '10 05:10

zdyn


People also ask

How do I resize canvas in GIMP?

The InstaGuide to Changing Canvas Size in GIMP This method is so quick, that you can do it in only two steps! Step 1: Open the Image menu, and click Canvas Size. Step 2: Enter your chosen settings, and click Resize. That's all there is to it!

How do you resize the canvas as per the size of an image?

To Resize the Canvas by Dragging: In Edit mode, select the Resize Canvas tool from the Toolbar at the top of the panel. Position your cursor over the edge or corner of your image until it changes into a double-pointed arrow. Drag the canvas' border to the desired size.

Can you drag to resize in GIMP?

Hold down the Command key while dragging a corner handle will scale the image proportionally. Choose the “Enter” key, or the Scale button in the dialog box to complete the change. The “M” key to selects the Move tool. Drag the adjusted image until it is positioned in the frame the way you want it to be.


1 Answers

Does your code work? If so, here's a better-looking version of the same code:

(let ((smaller-edge (min width height)))
  (gimp-image-resize image smaller-edge smaller-edge 0 0))
like image 112
Chris Jester-Young Avatar answered Oct 05 '22 08:10

Chris Jester-Young