Post Reply 

file-png-save2 and RUN-NONINTERACTIVE

Sep 4, 2012, 16:50 (This post was last modified: Sep 4, 2012 16:57 by drew.)
Post: #1
file-png-save2 and RUN-NONINTERACTIVE
I have developed a script which runs in RUN-INTERACTIVE mode. The script takes a 1024x1024 icon master file in xcf format and creates multiple png files scaled to the appropriate sizes for iPhone/iPad apps. It runs in RUN-INTERACTIVE mode because I want to be able to select the input file and the output directory.

The script works fine except for the line

(file-png-save2 RUN-NONINTERACTIVE newimage drawable outFile outFile 0 9 1 1 1 1 1 1 1)

A png file of the correct size gets created, but it is blank - just solid white background and nothing else. If I change the RUN-NONINTERACTIVE to RUN-INTERACTIVE on this line it works well except that the file save throws up the Export dialog box so that I have to click the Export button. I don't want this behaviour because the script will export the icon in about 8 different sizes and sitting clicking the Export button becomes tedious.


I would be really grateful if someone can point out the error of my ways.

Thanks


(PS I've just noticed, this should probably be in the Plugins forum - sorry - I tried to delete it and recreate it in that forum but don't have the access rights to do that)
Find all posts by this user
Quote this message in a reply
Sep 4, 2012, 20:19
Post: #2
RE: file-png-save2 and RUN-NONINTERACTIVE
The complete script (as it stands at the moment) is shown below...

(define (script-fu-iphone-export inFile outDir)
(let* (
(image (car (gimp-file-load RUN-INTERACTIVE inFile outDir)))
(newimage (car (gimp-image-duplicate image)))
(drawable (car (gimp-image-get-active-layer newimage)))
(outFile (string-append outDir "/icon.png"))
)
(gimp-context-set-interpolation INTERPOLATION-LINEAR)
(gimp-image-scale newimage 57 57)
(file-png-save2 RUN-NONINTERACTIVE newimage drawable outFile outFile 0 9 1 1 1 1 1 1 1)
(gimp-image-delete newimage)
)
)
Find all posts by this user
Quote this message in a reply
Sep 4, 2012, 21:16
Post: #3
RE: file-png-save2 and RUN-NONINTERACTIVE
As you're loading an xcf file, I presume it's comprised of more than one layer?

Your script will save a png file containing the active layer, which you seem to be finding is blank. When you run it interactively the image is being flattened into a single layer before saving, so you get the composite image saved.

Try adding a line to your script to flatten the image before saving (remembering to get the active layer again after flattening)

Kevin
Find all posts by this user
Quote this message in a reply
Sep 5, 2012, 09:12
Post: #4
RE: file-png-save2 and RUN-NONINTERACTIVE
Thanks Kevin - you set me on the right track. I had to merge the visible layers. The completed script is shown below should anyone else want to use it. It takes a source xcf file (I recommend 1024x1024 since that is the largest resolution you will need to produce for App store submission) and then resizes it to all the required sizes for various app icons and converts them to png (the required format).

Code:
(define (script-fu-iphone-export inFile outDir)
(let* (
    (image (car (gimp-file-load RUN-INTERACTIVE inFile inFile)))
    (workItems
      '(
        (57 "/icon.png")
        (114 "/icon@2x.png")
        (72 "/icon-72.png")
        (144 "/icon-72@2x.png")
        (29 "/icon-small.png")
        (58 "/icon-small@2x.png")
        (50 "/icon-small-50.png")
        (100 "/icon-small-50@2x.png")
        (1024 "/iTunesArtwork.png")
      )
    )
    (currentWorkItem)
    (outFile)
    (newimage)
    (drawable)
  )
  (gimp-context-set-interpolation INTERPOLATION-LINEAR)
  (while (not (null? workItems))
    (set! currentWorkItem (car workItems))
    (set! newimage (car (gimp-image-duplicate image)))
    (gimp-image-scale newimage (car currentWorkItem) (car currentWorkItem))
    (set! drawable (car (gimp-image-merge-visible-layers newimage CLIP-TO-IMAGE)))
    (set! outFile (string-append outDir (cadr currentWorkItem)))
    (file-png-save2 RUN-NONINTERACTIVE newimage drawable outFile outFile 0 9 1 1 1 1 1 1 1)
    (gimp-image-delete newimage)
    (set! workItems (cdr workItems))
  )
)
)
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  GIMP batch process script run-time error Paddy Landau 3 1,016 Apr 8, 2014 20:33
Last Post: Paddy Landau
  GIMP 2.8 won't open .jpg, .tif, .png, etc. powersown 16 4,662 Feb 3, 2014 02:01
Last Post: iForStyle007
  Batch conversion of PDF file ? eljay 4 6,422 Oct 21, 2013 10:20
Last Post: almien
  Run Deskew plugin from Python-Fu console ramonvaldezz 15 2,346 Aug 30, 2013 16:45
Last Post: ramonvaldezz
  [SOLVED] python plug-in, "RuntimeError ... gimp-file-load ... value out of range" Grafx 1 1,076 Mar 14, 2013 21:00
Last Post: Grafx

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS