Enlarging a picture to maximum screen height

Hi,

The script below, kindly supplied by ksstudio works well but the enlarged image is not as sharp as the same image enlarged by hand using Preview > Tools > Adjust Size. Can something be done about this?

-- http://kstudio.net/re.html

-- Open the Applescript Editor.
-- Create a new script and paste the following code:
on open theImages
	repeat with anImage in theImages
		tell application "Image Events"
			--Set the maximum dimension of the picture.
			-- If it is in landscape mode, it is the width.
			-- If it is in portrait mode, it is the height.
			set the targetSize to 1080
			set currentImage to open anImage
			set imageType to currentImage's file type
			scale currentImage to size targetSize
			tell application "Finder" to set newImage to (container of anImage as string) & "scaled" & (name of anImage)
			save currentImage in newImage as imageType
		end tell
	end repeat
end open
-- Save the script as an "Application".
--Drag your image to the new script Application.  You will get a new file with the new dimension.


Also, naming the enlarged image “scaled” (and image name) is less practical than Save As…followed by Replace.

Thank you for your help.

The script saves the modified file under a new name because the author is aware of the fact that enlarging a picture damage it so it’s fair to keep the original untouched.

If the picture is a landscape one, the result doesn’t fit the screen height because in this case, it’s the width which is set to 1080.

I applied the two schemes to the same original.
The file created by Preview has 220,466 bytes
The one created by the script has 237,089 bytes.
So it seems clear that they don’t use the same algorithm ” which is not really surprising.
I assume that the one used in Preview is more recent (and more efficient) than the old one used by ImageEvents which in fact is the one used by the Unix command Sips.

Yvan KOENIG (VALLAURIS, France) dimanche 24 août 2014 10:58:12

Hello.

A quick how to on sharpening images with imagemagick can be found here. I think it is best to install imagemagic via Macports. That way you get the dependencies, which I believe is ghostscript automagically installed, but you’ll probably need to have the developers tools installed as well. You might probably use gimp, if you intend to sharpen images manuallly.

Hi.

I don’t know the reason for the lesser sharpness, but with regard to the script itself, it should ideally close each image after processing it and quit Image Events at the end. Each Image Events ‘image’ has a ‘location’ property and it’s probably better to use this than a nested Finder statement, even though it requires some manipulation of a useless ‘POSIX path’ value. More trivially, it’s not really necessary to save the image ‘as’ something unless you want a different file type from the original.


-- Open the Applescript Editor.
-- Create a new script and paste the following code:
on open theImages
	--Set the maximum dimension of the pictures.
	-- If it is in landscape mode, it is the width.
	-- If it is in portrait mode, it is the height.
	set the targetSize to 1080
	tell application "Image Events"
		launch
		repeat with anImage in theImages
			set currentImage to (open anImage)
			scale currentImage to size targetSize
			set newImage to ((POSIX file (POSIX path of location of currentImage)) as text) & "scaled" & (name of currentImage)
			save currentImage in file newImage
			close currentImage
		end repeat
		quit
	end tell
end open
-- Save the script as an "Application".
--Drag your image to the new script Application.  You will get a new file with the new dimension.

By the way, when posting code here, it would be great if you could wrap it in [applescript] and [/applescript] tags so that it appears as above, with a link people can click to open it in their default script editors.