I am re-sizing numerous TIFF files, and creating compressed JPEG’s from them. Unfortunatly, I run across certain images that seem to have 2 or 3 MB of extra “bloat”. I’m not sure if this is a color profile or EXIF data or what. Is it possible to strip all un-necessary data out of the image when using Image Events?
The pertinent part of my script is:
if width > maxSize or height > maxSize then
scale imageFile to size maxSize
end if
save imageFile as JPEG in saveFolder
The whole script:
set inputFolder to quoted form of POSIX path of (choose folder with prompt "Select folder which contains the art file(s)" without invisibles)
set theFiles to paragraphs of (do shell script "mdfind -onlyin " & inputFolder & " 'kMDItemContentType = \"public.tiff\"'")
runConversion(theFiles)
on runConversion(theItems)
set saveFolder to choose folder with prompt "Save resized pictures where?" without multiple selections allowed and invisibles
tell application "Image Events"
launch
set maxSize to 1200
if (count items of theItems) is greater than 0 then
repeat with anItem in theItems
set imageFile to (open POSIX file (contents of anItem) as alias)
set {width, height} to dimensions of imageFile
if width > maxSize or height > maxSize then
scale imageFile to size maxSize
end if
save imageFile as JPEG in saveFolder
close imageFile
end repeat
else
display dialog "Nothing to convert."
end if
quit
end tell
end runConversion
Model: MacBook Pro
AppleScript: 1.10.7
Browser: Firefox 2.0.0.3
Operating System: Mac OS X (10.4)
I found that the embedded color profiles in each image were sometimes up to 5MB in size! This made what should have been a 64KB thumbnail into a 5MB+ file.
The newest version of my script removes the color profiles, and seems to be working well:
-- clear out and re-create our temporary directory structure
do shell script "rm -R -f /Users/Shared/Image_Import"
do shell script "mkdir /Users/Shared/Image_Import"
do shell script "mkdir /Users/Shared/Image_Import/big"
do shell script "mkdir /Users/Shared/Image_Import/thumbs"
set inputFolder to quoted form of POSIX path of (choose folder with prompt "Select folder which contains the art file(s)" without invisibles)
-- this section allows me to store the cd/dvd/folder path in a FileMaker database for reference
-- just remove this section if not using FileMaker
tell application "FileMaker Pro"
set contents of cell "g_import_path" of ¬
current record of layout "Tools_Image Import_detail" to inputFolder
end tell
-- process the images and thumbnails
set theFiles to paragraphs of (do shell script "find " & inputFolder & " | grep .tif")
runConversion(theFiles)
on runConversion(theItems)
set bigFolder to POSIX path of ("/Users/Shared/Image_Import/big")
set thumbFolder to POSIX path of ("/Users/Shared/Image_Import/thumbs")
tell application "Image Events"
launch
set maxSize to 1200
set thumbSize to 300
if (count items of theItems) is greater than 0 then
repeat with anItem in theItems
set imageFile to (open POSIX file (contents of anItem) as alias)
set {width, height} to dimensions of imageFile
if width > maxSize or height > maxSize then
scale imageFile to size maxSize
end if
save imageFile as JPEG in bigFolder
if width > thumbSize or height > thumbSize then
scale imageFile to size thumbSize
end if
save imageFile as JPEG in thumbFolder
end repeat
else
display dialog "Nothing to convert."
end if
quit
end tell
-- remove profiles from images (they sometimes add 5MB!)
do shell script "sips --deleteProperty profile " & POSIX path of bigFolder & "/*.jpg"
-- remove profiles from thumbnails (they sometimes add 5MB!)
do shell script "sips --deleteProperty profile " & POSIX path of thumbFolder & "/*.jpg"
end runConversion