• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

SDK: photo:requestJpegThumbnail generates an invalid file (Windows)

Community Beginner ,
Feb 15, 2023 Feb 15, 2023

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):

Invalid jpeg.png

 

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!

TOPICS
SDK

Views

370

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 15, 2023 Feb 15, 2023

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.

Votes

Translate

Translate
LEGEND ,
Feb 15, 2023 Feb 15, 2023

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 16, 2023 Feb 16, 2023

Copy link to clipboard

Copied

That's it! The solution works on both Windows & MacOS. Thanks a lot, not a bug then!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 16, 2023 Feb 16, 2023

Copy link to clipboard

Copied

LATEST

I always use "b". Modern Windows software is fine with Unix-style line endings ("\n").

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines