Re: Akua Sweets (is: resizing and saving as JPEG)
Re: Akua Sweets (is: resizing and saving as JPEG)
- Subject: Re: Akua Sweets (is: resizing and saving as JPEG)
- From: Brennan Young <email@hidden>
- Date: Wed, 11 Jul 2001 19:16:13 +0200
- Organization: Magic Lantern
Simon Forster <email@hidden> wrote
>
Using Akua Sweets, what's the logic for resizing an image and saving as a
>
jpeg?
If it's already JPEG, just use
scale image (imageAliasGoesHere) to {widthgoesHere, heightgoesHere}
My original script was a droplet. Here it is again.
on open droppedimg
scale image droppedimg to {320, 240}
end open
Did this not work for you?
It will modify the original file, so if you start with a JPEG, that's what
you will end up with. Maybe your original image is not in JPEG format?
It would help if you could give us a few more broad hints about what you are
trying to do. If you are exporting stills from a video, then the process
would be different than if you are starting with a JPEG file.
If you want to scale relative to the original image, you'll need to find out
its original size. Most of akua's draw sweets act on 'picture' objects
(picts), so you'll need to get that out first using 'the image from'
>
Do I need to "quickdraw" the image in a window of defined size to
>
scale it and then save the window contents?
No. Not unless you really want to. You can do everything 'off screen', which
is easier, and faster.
>
I find Akua Sweets' dictionary difficult to follow and the example scripts
>
have obviously been written by someone far more au fait with Akua than me!
Well, it's funny you should say that, they are written by the programmer of
the OSAX. I agree, there's some real esoterica in there, and learning to use
any dictionaries in the first place is not child's play. (I've never seen a
decent introduction to that.)
>
If anyone has some boilerplate AppleScript code which is well commented and
>
uses Akua Sweets to resize an image, would you zap it across to me?
Andy's script offered one approach. Did you try my original script? I can't
think of anything more basic. Try this one:
set prmpt to "Choose any image file"
set imgFile to (choose file with prompt prmpt)
-- check that Quicktime's image importer can read it
if (the image type in imgFile) is not "" then
-- get Mac 'pict' object from image file
set thePict to the image from imgFile
-- get picture information
set picInfo to the picture info for thePict
-- get picture
set picBounds to picture bounds of picInfo -- {left, top, right, bottom}
-- get width and height...
set defwi to (item 3 of picBounds as string)
set dr to display dialog "New width" default answer defwi
set wi to (the text returned of dr) as integer -- not foolproof
set defhi to (item 4 of picBounds as string)
set dr to display dialog "New height" default answer defhi
set hi to (the text returned of dr) as integer -- not foolproof
set scaledImage to (scale image thePict to {wi, hi})
set currentQuality to (picture compressed quality of picInfo)
if currentQuality is 0 then -- no quality setting
set currentQuality to 100
end if
set dr to display dialog "Compression quality" default answer currentQuality
set q to (the text returned of dr) as integer -- not foolproof
set newFile to (new file with prompt "Save as...")
store image scaledImage in newFile as "JPEG" with percent quality q
end if
This script, which you can run from script editor, is a whole lot more
manual than I would find useful, but at least it shows how to use the Akua
draw sweets in more detail.
Again, there is no error checking here. Most immediately, I would like to
trap the possibility of people entering non-numerical characters for width,
height and quality. I have a handler called 'integerFromUser' which gives
the user as many chances as she needs to correct hamfisted numerical input,
or cancel. I didn't want to confuse matters by putting in all the exception
handling. Just be aware that it is a good idea to anticipate likely errors.
Good luck!
--
_____________
Brennan