Image conversion troubleshooting

Hello all

I am trying to develop a script to convert an image from one format to another.

on convertImageType(targetImage, targetType)
	set theImage to targetImage
	tell application "Image Events"
		launch
		set theImageReference to theImage
		tell theImageReference
			save as targetType
			close
		end tell
	end tell
end convertImageType

convertImageType("test.psd", "JPEG")

This throws up the error “test.psd” doesn’t understand the save message.

All suggestions are welcome.

Thank you.

Derek :slight_smile:

Hi,

you should first open the file before processing it.
Another problem will occur specifying the format: as JPEG for example is an enumerated constant, not a string.

Thanks Stefan.

Could you explain what you mean by JPEG not being a string?

Thank you.

from the dictionary of Image Events

AS
as (enumeration)file type in which to save the image ( default is to make no change )
CONSTANTS

BMP
JPEG
JPEG2
PICT
PNG
PSD
QuickTime Image
TIFF

these formats are constants not strings (without quotes) like minutes in Standard Additions