Created
March 24, 2014 14:58
-
-
Save mauteri/9741757 to your computer and use it in GitHub Desktop.
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
public function closest_image_size( $width, $height, $photos ) { | |
foreach( $photos as $photo ) { | |
if( $width <= $photo['width'] && $height <= $photo['height'] ) { | |
$w = $photo['width'] - $width; | |
$h = $photo['height'] - $height; | |
if( !isset($source) ) { | |
$sum = $w + $h; | |
$source = $photo['source']; | |
} else if( $sum > ( $w + $h ) ) { | |
$sum = $w + $h; | |
$source = $photo['source']; | |
} | |
} | |
} | |
return $source; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also, this may want to be in it's own class.