Can you inspect my logic for resizing uploaded photos into thumbnails? This will be written in CFML but I just used basic if/then syntax not specific to any language.
Someone will upload a photo. I need to make a thumbnail version of it for display on a certain part of the website. A slightly larger thumbnail will be created for a majority of use across the site, and I will only need to resize according to width, making things much easier. HOwever, for this use, I need to make sure that the extra small thumbnail is both within a certain range of height and width.
The thumbnail needs to be no more than 90 pixels tall and 100 pixels wide. The script below checks to see if either the height or width exceed that range. Then it checks whether the height or width is the greatest out of range and scales the picture down according to that. For instance, if the height is more out of range than the width, that means if we scale the height back to 90, the width will mathematically also be pulled within appropriate range.
<!--- assume image data for 'local_photo_file' has been fetched,
using image_width and image_height as size of original photo -->
<!--- check if image size already meets restrictions for thumbnail size and
if a thumbnail already exists for photo. Thumbnail name is xs_local_photo_file --->
IF ((image_width GT 100) OR (image_height GT 90)) and NOT FileExists("xs_local_photo_file")>
IF image_width GT "#image_height#"
SET Size = "90"
SET width_Percentage = Evaluate(Size / image_width)
SET width_Percentage = Round(Percentage * 100)
SET height_Percentage = ""
ELSEIF image_height GT "#image_width#"
SET Size = "100">
SET height_Percentage = Evaluate(Size / image_height)
SET height_Percentage = Round(Percentage * 100)
SET width_Percentage = ""
/IF
ELSEIF ((image_width LT 100) AND (image_height LT 90)) and NOT FileExists("xs_local_photo_file")>
IF image_width GT "#image_height#"
SET Size = "90"
SET width_Percentage = Evaluate(Size / image_width)
SET width_Percentage = Round(Percentage * 100)
SET height_Percentage = ""
ELSEIF image_height GT "#image_width#"
SET Size = "100">
SET height_Percentage = Evaluate(Size / image_height)
SET height_Percentage = Round(Percentage * 100)
SET width_Percentage = ""
/IF
/IF
Someone will upload a photo. I need to make a thumbnail version of it for display on a certain part of the website. A slightly larger thumbnail will be created for a majority of use across the site, and I will only need to resize according to width, making things much easier. HOwever, for this use, I need to make sure that the extra small thumbnail is both within a certain range of height and width.
The thumbnail needs to be no more than 90 pixels tall and 100 pixels wide. The script below checks to see if either the height or width exceed that range. Then it checks whether the height or width is the greatest out of range and scales the picture down according to that. For instance, if the height is more out of range than the width, that means if we scale the height back to 90, the width will mathematically also be pulled within appropriate range.
<!--- assume image data for 'local_photo_file' has been fetched,
using image_width and image_height as size of original photo -->
<!--- check if image size already meets restrictions for thumbnail size and
if a thumbnail already exists for photo. Thumbnail name is xs_local_photo_file --->
IF ((image_width GT 100) OR (image_height GT 90)) and NOT FileExists("xs_local_photo_file")>
IF image_width GT "#image_height#"
SET Size = "90"
SET width_Percentage = Evaluate(Size / image_width)
SET width_Percentage = Round(Percentage * 100)
SET height_Percentage = ""
ELSEIF image_height GT "#image_width#"
SET Size = "100">
SET height_Percentage = Evaluate(Size / image_height)
SET height_Percentage = Round(Percentage * 100)
SET width_Percentage = ""
/IF
ELSEIF ((image_width LT 100) AND (image_height LT 90)) and NOT FileExists("xs_local_photo_file")>
IF image_width GT "#image_height#"
SET Size = "90"
SET width_Percentage = Evaluate(Size / image_width)
SET width_Percentage = Round(Percentage * 100)
SET height_Percentage = ""
ELSEIF image_height GT "#image_width#"
SET Size = "100">
SET height_Percentage = Evaluate(Size / image_height)
SET height_Percentage = Round(Percentage * 100)
SET width_Percentage = ""
/IF
/IF