-
-
Save rbk/ea5e73b390ac6f72b91c to your computer and use it in GitHub Desktop.
Calculate width based on max height
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function rbk_calculate_image_width_based_on_max_height( $filename, $max_height ) { | |
if( !empty($filename) ){ | |
$attributes = getimagesize( $filename ); | |
$image_width = $attributes[0]; | |
$image_height = $attributes[1]; | |
if( $image_width > $image_height ){ | |
return $image_width / $image_height * $max_height; | |
} else { | |
return $image_height / $image_width * $max_height; | |
} | |
} | |
} | |
$width = rbk_calculate_image_width_based_on_max_height( $logo, 46 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment