Inspiring
May 20, 2024
해결됨
SDK how to stack images using catalog:addPhoto( filePath, photo, 'above')
- May 20, 2024
- 1 답변
- 1064 조회
While importing photos from disk I'm struggling to stack these photos with existing photos in the Lightroom catalog.
My use case:
In my Lightroom catalog I have 2 images
On my disk I have 2 other images, noy yet loaded into Lightroom.
Their file name makes it clear which image on disk belongs to which image in the database
I'm using:
catalog:addPhoto( filePath, photo, 'above')What works well?
The images are loaded into Lightroom.
What works not?
They are not stacked.
Question: what am I missing?
Steps to reproduce
- See the attached images
- Import the two photos without "_nbg" into Lightroom
- Put the other two, without "_nbg" in the file name, into some directory.
- Change in my sample code below my directory name with the directory name you used above.
I downloaded the images from Unsplash.com
local LrApplication = import "LrApplication"
local LrDialogs = import "LrDialogs"
local LrFileUtils = import "LrFileUtils"
local LrFunctionContext = import "LrFunctionContext"
local LrPathUtils = import "LrPathUtils"
local logFilename = "StackPhotos"
local myLogger = import 'LrLogger'( logFilename )
myLogger:enable( "logfile" )
local catalog = LrApplication.activeCatalog()
local function findByName(filename)
local foundPhoto = catalog:findPhotos {
searchDesc = {
criteria = "filename",
operation = "all",
value = LrPathUtils.replaceExtension(filename, "jpg"),
value2 = "",
}
}
return foundPhoto
end
local function main()
myLogger:info("Main: start")
--Import both photos WITH background in Lightroom: everyday_matters-closedEyes.jpg and Reinaldo Kevin.jpg
--Put in the directory of your chosing the 2 images without background: everyday_matters-closedEyes_nbg.png and Reinaldo Kevin_nbg.png
-- BTW _nbg stands for no background
local destinationPath = LrPathUtils.standardizePath("D:\\Temp\\Lightroom Burned Exports\\output")
myLogger:info("destinationPath", destinationPath)
-- Prepare database for adding photos
catalog:withWriteAccessDo ("Stack", function ()
-- Loop the folder with the image with no background
for filePath in LrFileUtils.directoryEntries( destinationPath ) do
-- Determine the file name of the original photo by removing the "_nbg"
local leafName = LrPathUtils.leafName(filePath:gsub("_nbg", ""))
local photo = findByName(leafName)[1]
if (photo) then
myLogger:info("Image found", leafName, photo, photo:getFormattedMetadata("fileName"))
catalog:addPhoto( filePath, photo, 'above')
else
myLogger:info("Image NOT found", leafName)
end
end
end)
LrDialogs.message("Stacking photos", "Finished stacking photos")
end
LrFunctionContext.postAsyncTaskWithContext ("Stack photos", function( context )
LrDialogs.attachErrorDialogToFunctionContext( context )
main()
end)The log file
05/20/2024 16:18:37 INFO Main: start
05/20/2024 16:18:37 INFO destinationPath D:\Temp\Lightroom Burned Exports\output
05/20/2024 16:18:37 INFO Image found everyday_matters.png LrPhoto( id "126" ) everyday_matters.jpg
05/20/2024 16:18:39 INFO Image found Reinaldo Kevin.png LrPhoto( id "121" ) Reinaldo Kevin.jpg
