Please enable / Bitte aktiviere JavaScript!
Veuillez activer / Por favor activa el Javascript![ ? ]
How to resize layer to fit canvas using Gimp? - bug-code.com Q&A

How to resize layer to fit canvas using Gimp?

0 like 0 dislike
51 views
asked by (4.3k points) | 51 views

1 Answer

0 like 0 dislike

Try to enter this code on Python filters - python- console:

img = gimp.image_list()[0]; layer = img.layers[0]; factor = min (float(img.width) / layer.width, float(img.height) / layer.height); layer.scale(int(layer.width * factor), int(layer.height * factor)); layer.set_offsets((img.width - layer.width) / 2, (img.height - layer.height) / 2)

 

Also, you can use a script to pick the image or layer to resize. Paste the information below as a file edit - preferences - folders - plug-ins and restart GIMP

#! /usr/bin/env python
# coding: utf-8
 
from gimpfu import *
 
def scale_layer_to_canvas_size(img, layer):
    pdb.gimp_image_undo_group_start(img)
    factor = min (float(img.width) / layer.width,
                 float(img.height) / layer.height)
 
    layer.scale(int(layer.width * factor), int(layer.height * factor))
    layer.set_offsets((img.width - layer.width) / 2,
        (img.height - layer.height) / 2)
    pdb.gimp_image_undo_group_end(img)
 
register("scale-layer-to-canvas-size",
    "Scale layer to canvas size",
    "Scales the layer to canvas size, keeping the aspect ratio",
    "João S. O. Bueno", "Public domain", "2014",
    N_("Scale layer to canvas size..."),
    "*",
    [(PF_IMAGE, "image",       "Input image", None),
     (PF_DRAWABLE, "layer", "Input drawable", None), ], [],
    scale_layer_to_canvas_size,  menu="<Image>/Layer/",
    )
 

main()
answered by (8.5k points)
Welcome to Bug-code Q&A, where you can ask questions and receive answers from other members of the community.

24.8k questions

46.2k answers

0 comments

12.7k users

24,788 questions
46,220 answers
0 comments
12,685 users