Question

I am a little new to Script-Fu and need to do a resolution change from 600DPI to 300DPI and then a canvas resize to 1000px W by 2000px H while leaving the actual image size intact. Otherwise my picture gets stretched.

I'm sure the script should go something along the lines of like this one I've found. But this one in particular complains about my image being indexed and it want's an RGB image. Which I don't want to do...

;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
; File = script-fu-grow-canvas.scm
; function name script-fu-grow-canvas
;
;=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
;
( define
  ( script-fu-grow-canvas
    theImage
    theDrawable
  )
  ;
  (gimp-image-undo-group-start theImage)

  ( let*
    (
      ; Define local variables
      ;    imageWidth, imageHeight, centerX, centerY
      ; Measure the height and width of the image.
      ; Calculate the center
      ( imageWidth ( car ( gimp-drawable-width theDrawable )))
      ( imageHeight ( car ( gimp-drawable-height theDrawable )))
      ( centerX ( / imageWidth 2 ))
      ( centerY ( / imageHeight 2 ))
      ( tenthWidth ( / imageWidth 8 ))
      ( tenthHeight ( / imageHeight 8 ))
      ( borderx tenthWidth )
      ( bordery tenthHeight )
      ( newWidth 0 )
      ( newHeight 0 )
      ( dummyLayer 0 )
      ( layername "DummyLayer" )
      ;
    ) ; End of Variable Declaration
    ; if Aspect ratio widget is unchecked make X and Y
    ;   length the greater of the two.
    ( set! newWidth ( + imageWidth ( * borderx 2 )))
    ( set! newHeight ( + imageHeight ( * bordery 2 )))
    ;
    ( set! dummyLayer (car ( gimp-layer-new
                theImage
                imageWidth
                imageHeight
                0
                layername
                10
                0 ))
    )
    ( gimp-image-add-layer theImage dummyLayer 1 )
    ( gimp-layer-resize dummyLayer
                newWidth
                newHeight
                borderx
                bordery )
    ( script-fu-para-tat-layer
          theImage
          dummyLayer
          layername )

    ( gimp-image-resize-to-layers theImage )
    ;
    ( gimp-drawable-set-visible dummyLayer FALSE )
    ( gimp-image-set-active-layer theImage theDrawable )

  ) ; END let*
  (gimp-image-undo-group-end theImage)

) ; END define

( script-fu-register "script-fu-grow-canvas"  ; Function Name
  "02 Expand Canvas"    ; Menu Label
  "Expand the image canvas based on image
   size"        ; Function Description
  "Stephen Kiel"         ; Author
  "2011, Stephen Kiel"   ; Copyright
  "December 2011"        ; Creation Date
  "*"                    ; Valid Image Type
  SF-IMAGE "theImage"  0
  SF-DRAWABLE "theDrawable" 0
) ; End script-fu-register
( script-fu-menu-register
     "script-fu-grow-canvas" "<Image>/Flowzilla/Flow - Standard")
Was it helpful?

Solution

You are using gimp-layer-new to create a new RGB type layer - this type of layer cannot be added to an indexed image.

Lots of other script-fu calls might be restricted for indexed images - and there are ways to work around them - but it is not the case here

The value with the layer type is the "0" you put just before the "layername" parameter. According to the documentation (visible using the "Procdure Browser" in GIMP's help menu), there is an enumaration for layer types, and you should be passing INDEXEDA-IMAGE to it, for indexed images (0 is for RGB-IMAGE).

It is important to use the named constants as they are shown in the documentation, not the numbers they represent, since these numbers are not guaranteed to remain the same across versions, and due to the fact that using the names adds context and readability to your code.

Likewise, you should not use "10" for the layer mode, and rather the apropriate constant name that suits you (LIGHTEN-ONLY-MODE in GIMP 2.6)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top