6 Replies Latest reply on Oct 21, 2010 2:25 PM by TheRealAgentK

    Resize image and maintain aspect ratio

    tomtomtom

      Hello all

       

      I'm trying to resize big JPEGs and maintain the aspect ratio. I actually managed to write the code but it is huge so I wonder whether there is an easy way. The next question is regarding the picture resolution. I resize pictures which come in 600 and more dpi. Is there a way ColdFusion can resize and decrease the resolution to 72dpi?

       

      Thanks for hints and links

        • 1. Re: Resize image and maintain aspect ratio
          Adam Cameron. Level 5

          Have you read the docs on imageResize():

          http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-79 61.html

           

          ?

           

          width

          Required. New width of the ColdFusion image.

          If this value is blank, the width is calculated proportionately to the height.

          height

          Required. New height of the ColdFusion image.

          If this value is blank, the height is calculated proportionately to the width.

           

          Not too sure about the DPI issue, but have you read over the docs for all the image functions?

           

          --
          Adam

          • 2. Re: Resize image and maintain aspect ratio
            tomtomtom Level 1

            Dear Adam

             

            Many thanks for your solution - I wasn't reading careful enough the cfimage and resizeimage tutorials! I quickly went through the image functions and unfortunately did not find anything yet regarding my DPI issue...

             

            May be someone else knows something?

             

            Thanks again!

            • 3. Re: Resize image and maintain aspect ratio
              TheRealAgentK Level 2

              DPI are reasonably irrelevant as long as you're resizing the images for screen use. DPI is relevant for print though as it describes the "density" of your pixels.

               

              If your images are 600dpi, I would assume tehy have really high resolution, for screen use you just resize them to the pixel dimensions you need.

               

              Also, have a read of this thread re dimensions vs. DPI: http://www.houseoffusion.com/groups/cf-talk/thread.cfm/threadid:54696

               

              Cheers

              Kai

              • 4. Re: Resize image and maintain aspect ratio
                tomtomtom Level 1

                Hello Kai

                 

                Many thanks for your post. I checked the posts on houseoffusion.com. It does help understanding all technical issues but actually has not a lot to do with my question. May be I try to ask it in another way:

                 

                I'm storing images which are supposed to be printed on a server. So these images need to be in "good quality". The images are initially scanned from dias in a resolution of 600 dpi. I do not want my database application to show the initially scanned images. Imagine I have a page showing 10 pics at the time - I would need to download hundreds of MB. I programmed my CF application to create thumnails in 100 x 100 pixels dimension. And these thumbnails come in a resolution of 600 dpi which does not make any sense because they are intended to be displayed on a screen. So 72 dpi would be enough. Another reason is the size of the thumb. In 600 dpi it is much bigger than if it would come in 72 dpi. So, is there a way to work on the resolution of the image with CF?

                 

                Thank you very much for input.

                 

                Regards

                Tom

                • 5. Re: Resize image and maintain aspect ratio
                  ilssac Level 5

                  tomtomtom wrote:

                   

                  And these thumbnails come in a resolution of 600 dpi

                   

                  No they don't.  Files do not have dpi -- OUTPUT (and some INPUT) devices have dpi.

                   

                  FIles have resolution, color depth, file format and compression.

                   

                  Your are mixing up OUTPUT quality with FILE data.

                   

                  You have an image file that is 100px by 100px.  That is the FILE data.  Thus the file has 10,000 pixels of data (not a lot for a picture).

                   

                  Now if you OUTPUT that to a monitor at 72dpi those 10,000 pixels will be displayed in an area of ~1.38 inches by ~1.38 inches.

                   

                  If you OUTPUT that to a printer at 300dpi it will be displayed in an area of ~0.33 inches by ~0.33 inches.

                   

                  The quality of the image file is the same, but the output determines how small the dots are for each pixel and thus how large the overall image is.

                   

                  The things that affect the quality of the image file are how many dots there are in the file (resolution) how much those dots are squeezed (compression) and file format (lossless versus lossy) and how many colors can be used for each dot (color depth)

                  • 6. Re: Resize image and maintain aspect ratio
                    TheRealAgentK Level 2

                    Hey Tom,

                     

                    when you create a thumbnail from your original image (having a very high resolution) and that thumbnail is 100x100 pixels, that's all it is to it really. Your thumb will then render 100x100 on the screen and given that the _output_ device screen usually has 72 dpi it'll use the appropriate size in inches.

                     

                    Your thumbnail would not "have" 600 dpi, there's no such thing defined for image/file data as such. Just create an thumbnail having the resolution you want and need for your web output and you're done.

                     

                    Hope that makes sense, if not ask.

                     

                    Cheers

                    Kai

                    1 person found this helpful