How to create a layered PSD file from command line?

后端 未结 6 865
轻奢々
轻奢々 2020-12-04 16:06

I need to create a layered PSD file with ImageMagick or any other command-line tool available on Linux platform. Since I need to do this on Linux server, I

6条回答
  •  鱼传尺愫
    2020-12-04 16:48

    I agree with Jon Galloway, the Gimp console is a better choice. Here is my script:

    (define (pngtopsd width height png-paths psd-path)
    (define (add-layers image png-paths) 
        (if (null? png-paths) 0 
            (let* 
                ((png (car png-paths))
                (new-layer (car (gimp-file-load-layer 0 image (car png)))))
    
                (gimp-image-insert-layer image new-layer 0 -1)
                (gimp-item-transform-2d new-layer 0 0 1 1 (cadr png) (caddr png) (caffffdr png))
                (add-layers image (cdr png-paths))
            )
        ))
    
    (let* 
        ((png (car png-paths))
        (image (car (gimp-file-load 1 (car png) (car png))))
        (drawable (car (gimp-image-get-active-layer image))))
    
        (gimp-image-resize image width height 0 0)
        (gimp-item-transform-2d drawable 0 0 1 1 (cadr png) (caddr png) (caffffdr png))       
        (add-layers image (cdr png-paths))
        (file-psd-save 0 image drawable psd-path psd-path 1 0)
        (gimp-image-delete image)
    ))
    

    You just need put this script into file with name "pngtopsd.scm" inside your gimp "script" directory ("c:\Program Files\GIMP 2\share\gimp\2.0\scripts\" for Windows) and you can create layered PSD from list of PNG pictures with transformation (translation or rotation) of each layer. Usage sample:

    gimp-console-2.8.exe -i -b              ^
      "(pngtopsd (list                      ^
       (list \"c:/../1.png\" 0 500 500)     ^
       (list \"c:/.../2.png\" 0.7 200 1000) ^
       (list \"c:/.../3.jpg\" -0.5 1000 0)) ^
       \"c:/.../result.psd\")"
    

    There (list \"c:/.../2.png\" 0.7 200 1000) means:

    • 0.7 is the rotation angle of picture (in radians)
    • 200 1000 is x and y shift on an image

提交回复
热议问题