Archive for August, 2011
Determine IMG Scale Ratio
by webmasterjunkie on Aug.27, 2011, under Coldfusion, Internet, Programming, Web
Well, recently I had to vertically center an image in a square DIV. This had to be done with the image being scaled to a specific width, 90px. I know there are probably hundreds of ways to do this, but this is the one that I used to determine how much top margin to set on the image in order to center it vertically.
<cfobject type="JAVA" action="Create" name="tk" class="java.awt.Toolkit"></cfobject> <cfobject type="JAVA" action="Create" name="img" class="java.awt.Image"></cfobject> <!--- requires knowing the desired width of the image/div ---> <cfset imgDims = 90 /> <cfscript> imagePath = ExpandPath ("/uploads/Image/sponsors/#sm_image#"); img = tk.getDefaultToolkit().getImage("#imagePath#"); imgWidth = img.getWidth(); imgHeight = img.getHeight(); percentage = (imgDims / imgWidth) * 100; newHeight = round((imgHeight * percentage) / 100); margin = (imgDims - newHeight) / 2; </cfscript>

Connect
Enter your WordPress.com blog URL
http://.wordpress.com
Proceed