4 Replies Latest reply: Apr 8, 2012 12:41 PM by clvrmnky RSS

    access photo aspect ratio (square, portrait, landscape)

    ryan_rowell Community Member

      I need to know what the aspect ratio of an image is so i can apply css properties to it depending on it being square, landscape, or portrait. is there a propery that will return this information?

        • 1. Re: access photo aspect ratio (square, portrait, landscape)
          areohbee Community Member

          photo:getRawMetadata( 'croppedDimensions' )

          • 2. Re: access photo aspect ratio (square, portrait, landscape)
            ryan_rowell Community Member

            so?:

             

            local function whatOrientation ( imageID )

             

            local variableName = photo:getRawMetadata('croppedDimensions')

            local outPutName = nil

             

            if variableName.width > variableName.height then

                 outPutName = "landscape"

            else

                 outPutName = "portrait"

            end

             

            if variableName.width == variableName.height then

                 outPutName = "square"

            end

             

            return outPutName

             

            end

             

             

            then use it in the galleryinfo.lrweb somewhow?

             

            I am beyond new to using lua, and have a 15 year ago background in C that was never continued so I am way out of practice.

             

            my goal is to set each thumbnail generated from the web gallery with a class selector for my css styles. I think what i am looking to do would be best setup in javascript but i would love if lightroom (lua in this case) can take some of the load off. so in the end i might have a gallery with 20 images, and 20 thumbnails, each thumbnail depending on its orientation I would set the selector when the gallery is generated.  Any theory where to start or where I should be calling this function.

             

            thanks again for responding,

             

            Ryan

            • 3. Re: access photo aspect ratio (square, portrait, landscape)
              areohbee Community Member

              Hi Ryan,

               

              I'm not familiar with Lr web gallerys, but I think you've got the idea aspect-ratio/orientation-wise.

               

              Rob

              • 4. Re: access photo aspect ratio (square, portrait, landscape)
                clvrmnky Community Member

                You probably want to have outputName set to something valid, unless the caller can handle nil. LrPhoto:getRawMetadata() can return nil, as well, so you might want to check for nil before trying to use it.

                 

                Also, note that LrPhoto:getRawMetadata() will need to be called from within an LrTask, either one you create yourself, or one provided by the SDK context you are running this in.