Skip to main content
Known Participant
January 25, 2009
Question

resizing images - portrait and landscape

  • January 25, 2009
  • 1 reply
  • 398 views
Hi,

I am uploading and resizing images(see code), I want to resize them to 200px by 150px if landscape and 150px by 200px if portrait. How can I determine the orientation of the image?
    This topic has been closed for replies.

    1 reply

    January 25, 2009
    Well, first of all you would need to know what the initial image dimensions are. And the way to do this is to get the current images height and width from reading the image. You would then compare the width number to the height number and if the width is greater than the height, you know that it's more of a landscape photo...and vice versa.

    Try this code:

    <cfimage action="read" source="#expandPath("graphics/corner.png")#" name="myImage" />

    <cfdump var="#variables.myImage#" />

    <cfif variables.myImage.width gt variables.myImage.height>
    Landscape
    <cfelseif variables.myImage.width lt variables.myImage.height>
    Portrait
    <cfelseif variables.myImage.width eq variables.myImage.height>
    Square
    <cfelse>
    Something else for whatever reason.
    </cfif>

    At least, I think this is how you'd do it. I know it's not the most elegant way...you might want to look at ColdFusion image functions rather than reading the whole image in, I think there are functions just to get width and height, which I imagine should give you better performance.

    Good luck,
    Mikey.