GraphicConverter Scripting Questions

I’m not knowledgeable about Applescript, but need to use it in order to convert uploaded images on a Webserver. Am using GraphicConverter to do the image manipulation. Want to convert any image that is uploaded to two versions - one 280 pixels width and the second 100 pixels wide.

Have this code… which does work

tell application "GraphicConverter PPC"
	(activate)
	(open "G4-1:desktop folder:photo_drop_box:uploadedimage.jpg")
	get image dimension of window 1
	set wide to item 1 of result
	set scale_factor to (280 / wide)
	scale window 1 horizontal scale_factor vertical scale_factor
	save window 1 in "G4-1:desktop folder:photo_drop_box:uploadedimage_280.jpg" as JPEG
	get image dimension of window 1
	set wide2 to item 1 of result
	set scale_factor2 to (100 / wide2)
	scale window 1 horizontal scale_factor2 vertical scale_factor2
	change colors window 1 to bit depth "16"
	save window 1 in "G4-1:desktop folder:photo_drop_box:uploadedimage_100.jpg" as JPEG
	close window 1 without saving
end tell

… but the problem is that I need to convert the script to apple_events for use by our app server and want to stipulate an exact pixel width rather than a scale factor, as outlined in the code above… I can’t see anywhere in the GC library that I can stipulate a specific width for an image… other than to scale with factors… is this true?

Any insight - much appreciated.

GraphicConverter doesn’t let you specify a target pixel width.
Gotta’ scale. However, I needed to do exactly what you’re doing just this morning.
I ended up using some math to translate scaling to a fixed pixel width.


                   set theDim to (image dimension of window 1)
                   set myWidth to item 1 of theDim
		set myHeight to item 2 of theDim
		if myWidth > 770 then
			set myPerc to (770 / myWidth)
			scale window 1 horizontal myPerc vertical myPerc
			set newName to (text 1 through -5 of myName)
			save window 1 in ("Jasper:Users:tjm:Desktop:JPG_OUT:" & (newName & ".jpg")) with makeCopy
		else
			set newName to (text 1 through -5 of myName)
			save window 1 in ("Jasper:Users:tjm:Desktop:JPG_OUT:" & (newName & ".jpg")) with makeCopy
		end if
		close window 1 saving no

The point here being that I needed my ouptut images to always be 770 pixels wide or less.