6

In AppleScript, I can export photos from Apple Photos. There are two options:

  • using originals, which discards all modifications I've made
  • not using originals, which exports them at 100% quality.

The export at 100% quality is practically uncompressed, even when the original photo is more compressed. This ends up taking more space than the original, effectively upsampling the photo, at no added benefit.

Is it possible to keep the original quality, but not lose the edits made in Photos?

Note that a switch for quality exists in Photos, as per screenshot below.

enter image description here

EDIT

I ended up writing and using this. Note that this does still NOT solve my problem, as explained in the comments, but it gives me a suitable approximation.

(* 
Export Apple Photos
===================

Exports all photos in Apple Photos library and reduces them to 90% quality. 
The photos are in their current version (as opposed to the original). 
Quality reduction is done with `mogrify` as setting the quality isn't 
possible (nor it is possible to get the current quality -- everything 
gets exported at 100%). For more on this issue see [1].


TODO
----

* Albums in the top folder (i.e. outside any folder) aren't exported. 
  Only albums in folders are exported. To list them run this::

    tell application "Photos"
        repeat with alb in albums
            log (get name of alb)
        end repeat
    end tell

References
----------

[1] https://apple.stackexchange.com/questions/410229/applescript-photos-export-quality

*)


-- main
tell application "Photos"
    repeat with topFolder in folders
        my processFolder(topFolder, 0, (get name of topFolder))
    end repeat
end tell


-- recursively scan folders and export albums
on processFolder(fold, level, dirpath)
    tell application "Photos"
        log "Folder " & (get name of fold)
        repeat with subFolder in (get folders of fold)
            set subPath to dirpath & "/" & (get name of subFolder)
            my exportAlbum(subFolder, subPath)
            my processFolder(subFolder, level + 1, subPath)
        end repeat
        my exportAlbum(fold, dirpath)
    end tell
end processFolder


-- export all albums in folder `f`
on exportAlbum(f, relativePath)
    set dest to "/Volumes/DATA/ApplePhotos/" as POSIX file as text -- the destination folder (use a valid path)
    
    tell application "Photos"
        repeat with i in (get albums of f)
            set tFolder to (the POSIX path of (dest as string) & relativePath & "/" & (get name of i)) as POSIX file as text
            repeat 1 times
                tell application "Finder"
                    if exists tFolder then
                        log "Skipping album " & (get name of i)
                        exit repeat
                    end if
                end tell
                log "Album " & (get name of i) & " -> " & tFolder as POSIX file as text
                my makeFolder(tFolder) -- create a folder named (the name of this album) in dest
                with timeout of 120 * 60 seconds -- 2 hours
                    
                    export (get media items of i) to (tFolder as alias) without using originals
                    my reduceSize(tFolder)
                end timeout
            end repeat
        end repeat
    end tell
end exportAlbum


-- util mkdir
on makeFolder(tPath)
    do shell script "mkdir -p " & quoted form of POSIX path of tPath
end makeFolder


-- util shell script to reduce file size (quality 90)
--   note: it checks folder is not empty, otherwise mogrify will fail.
on reduceSize(tPath)
    set dirpath to quoted form of POSIX path of tPath & "/*.jpeg"
    do shell script "ls " & dirpath & "; if [ $? -eq 0 ]; then /usr/local/bin/mogrify -quality 90 " & dirpath & "; else echo No files in folder " & dirpath & "; fi"
end reduceSize

2
  • 1
    RE: "Note that a switch for quality exists in Photos, as per screenshot below." -- I believe that only exists when exporting via the UI, not the AppleScript export command of Photos. If you need to modify those settings for the export, then use UI Scripting for the export. – user3439894 Feb 2 at 13:30
  • @user3439894 any option to export with modifications using HEIC? – laktak Feb 2 at 15:37
1
+100

You could use the third-party tool ImageMagick, which can perform a wide variety of image transformations, including converting to a lower quality. You can install it with Homebrew with brew install imagemagick. You would include it through the do shell script command, for example do shell script 'convert input.png -quality 85% output.jpg'.

4
  • The modifications already exist as metadata (like color corrections or cropping). So you could apply the modifications to the exported original. Not sure if you can get to the metadata though. – laktak Feb 3 at 15:52
  • This is what I ended up doing. But as you don't get the original quality of the jpeg photo, if you set it to 85% you may be dropping information (say it was originally 90%) or even upsampling, which occupies more space with no added quality. I ended up exporting it all at 90% which is fine for my purposes. – gozzilli Feb 8 at 22:08
  • @gozzilli I'll award the bounty here because it was the most helpful and got me a step to my workaround. – laktak Feb 9 at 12:41
  • @laktak great, I've also edited the original question with the solution I'm using (which also follows the same principle as this answer) – gozzilli Feb 9 at 13:41
1

There is no such thing as the "original" quality when you're dealing with JPEG's.

This answer on Photo.SE explains that when you open a JPEG, it's decoded and decompressed. When you apply changes, the application does this on the decompressed version in memory. Then, when you hit export, the application compresses the image again taking the JPEG quality into account.
This other answer on Photo.SE has more information on JPEG-to-JPEG exports.

You don't indicate explicitly why you want the "original" quality, but I think you are looking to approach the same file size as the original JPEG.
In that case, try out the different quality levels (low, medium, ...) to check which level gives you approximately the same file size as the JPEG file you started with. Then use UI scripting to export the photos at the desired quality level.

7
  • JPEG is just one of the options, it also has PNG or TIFF though there is no HEIC in the list. I'd want the original because compression reduces the image quality. – laktak Feb 3 at 15:49
  • @laktak Could you perhaps elaborate on your final goal with a bit more context? – Saaru Lindestøkke Feb 3 at 16:00
  • My goal would be to export photos and videos in their original format with no loss of quality. If the photo/video was modified in any way (color corrections, cropping, etc.) that should be applied to the exported media as well. A good compromise would be to export unmodified as original and the modified ones with some compression ... – laktak Feb 4 at 8:01
  • Perhaps you can create a new question (or you already have)? That would allow you to include more details and show previous research. The current question seems to touch on a small part only. – Saaru Lindestøkke Feb 4 at 8:40
  • I've already posted the bounty here but I'll do that if no solution is found. – laktak Feb 4 at 8:52
0

Utilize the HEIC format by exporting originals. Multiple operating systems support this including windows via a plugin.

https://discussions.apple.com/thread/7644152

1
  • Yes but how do you keep your adjustments to the pictures when doing so? – laktak Feb 6 at 19:03
0

The Photos library contains AAE files but they are proprietary and can't be exported.

Quicktime will use an AAE file (if you place it next to the original mov) for slow motion videos to mark where the positions (but again it can't be exported).

I found that you can filter the photos by 'edited' (though it is not always accurate and sometimes shows unmodified photos as edited)

  • so I exported the modified photos as JPG (with modifications)
  • and all unmodified media in their original quality (HEIC/mov)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .