Copy link to clipboard
Copied
Hello,
I need to export thumbnails of photos I've selected with the photo:requestJpegThumbnail method. While it works great on MacOS, on Windows the exported image is not valid (no preview + error while opening the file):
Tested on:
- Mac OS 13.0.1 + Lr Classic 12.1 & 12.2: works well
- Windows 10 21H1 + Lr Classic 12.1 & 12.2 : FAIL
Steps to reproduce:
- Create a c:/temp folder (or change the hardcoded export folder in the source code)
- Install the plugin in Lr
- Select at least one photo to export in the Library module
- Select Library > Plug-in extras > Test export thumbnails
- Check the file(s) in the c:/temp folder
The plugin can be downloaded here: https://pierrepichot.com/wp-content/uploads/2023/02/test.lrdevplugin.zip
The code is the following:
local LrTasks = import 'LrTasks'
local LrApplication = import 'LrApplication'
local catalog = LrApplication.activeCatalog()
LrTasks.startAsyncTask(function()
LrTasks.startAsyncTask(function()
local selectedPhotos = catalog.targetPhotos
for _, photo in ipairs( selectedPhotos ) do
local uuid = photo:getRawMetadata("uuid")
local previewname = uuid .. ".jpg"
local folder = "c:\\temp\\"
--local folder = "/Users/Me/Documents/"
local holdRefObj = photo:requestJpegThumbnail(1600, 1000, function( success, failure )
local f = io.open(folder .. previewname,"w")
f:write(success)
f:close()
end )
LrTasks.sleep(.5)
end
end )
end )
Thanks!
Use "wb" rather than "w" as the mode for io.open(). I think "b", binary mode, prevents the translation of "\n" to the old-fashioned "\r\n" on Windows systems.
Copy link to clipboard
Copied
Use "wb" rather than "w" as the mode for io.open(). I think "b", binary mode, prevents the translation of "\n" to the old-fashioned "\r\n" on Windows systems.
Copy link to clipboard
Copied
That's it! The solution works on both Windows & MacOS. Thanks a lot, not a bug then!
Copy link to clipboard
Copied
I always use "b". Modern Windows software is fine with Unix-style line endings ("\n").