Set Image Resolution / Scaling by Pixels

Hi all,

I have searched for this option for a few days now, but it looks like it doesn’t work at all, so I’d appreciate, if anyone could either give me a hint, or confirm that it doesn’t work.

Basically I want to scale down images (in my case with Graphic Converter) with AppleScript to a certain size. Since the original images can be in different sizes, I don’t want to scale them down by the percentage, but by the pixels, i.e. instead of scaling them down by 0.5 (50%), I’d like to scale them down to 256 pixels.

So the big question is now: Is there a quick way to do so? I’m not looking for a workaround (I’ve seen some really huge ones), as the effort for such a workaround would by far be higher than simply resizing the images manually.

Many thanks in advance.

Lasse79, Im not a user of Graphic Converter. I use Photoshop mostly for Image manipulation. Do you have this software? If not you should also include AppleScript’s Image Events or SIPS in your searches of the forum. Both of which can process image files without GUI. If you have not already done so. Should be plenty of examples.

Hi.

I’m not well up on Graphic Converter, but Image Events (which comes with the system) can do what you want.

set f to (choose file)

set savePath to f as text
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to "."
set savePath to text 1 thru text item -2 of savePath & " (scaled)." & text item -1 of savePath
set AppleScript's text item delimiters to astid

tell application "Image Events"
	launch
	tell (open f)
		scale to size 256 -- Pixel length of long axis.
		save in savePath
		close
	end tell
	quit
end tell

Oh there you go. NG has come in and NO need to even search. :smiley:

Very cool. Thanks a million to both of you. I’ve seen quite a few posts with Image Events, but I thought, it’s some 3rd party application.
Now I’ll see, if I understand the script Nigel wrote. :slight_smile:

http://www.macosxautomation.com/applescript/imageevents/index.html

Not 3rd party just hidden from the GUI.

The thing being ‘told’ in the middle of Image Events part is the result of opening the file ” that is, the front ‘image’ in the application. That section could be written:

tell application "Image Events"
	launch
	set theImage to (open f)
	scale theImage to size 256 -- Pixel length of long axis.
	save theImage in savePath
	close theImage
	quit
end tell

As with all of Apple’s faceless, scriptable-only applications, you ‘launch’ Image Events rather than ‘run’ or ‘activate’ it. This just loads it as an application into memory without making it run through any start-up procedure or come to the front.