Created
February 18, 2010 07:52
-
-
Save brettflorio/307454 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
<?php | |
// SNIPPET: PhotoDimensions | |
// | |
// Parameters: | |
// image | |
// classWide | |
// classTall | |
if (!$image) { | |
return ''; | |
} | |
$classWide = isset($classWide) ? $classWide : 'photoWide'; | |
$classTall = isset($classTall) ? $classTall : 'photoTall'; | |
$classSquare = isset($classSquare) ? $classSquare : $classTall; | |
$width = isset($width) ? $width : 400; | |
$size = GetImageSize( $_SERVER['DOCUMENT_ROOT'] . $image ); | |
$w = $size[0]; | |
$h = $size[1]; | |
if ($mode == 'maxwidth') { | |
if ($w > $width) { | |
$output = '/assets/snippets/thumb/phpThumb.php?src=' . $image . '&w=' . $width; | |
} else { | |
$output = $image; | |
} | |
} elseif (!$mode) { | |
if ( $w > $h ) { | |
$output = $classWide; | |
} elseif ( $w < $h ) { | |
$output = $classTall; | |
} else { | |
$output = $classSquare; | |
} | |
} elseif ($mode == 'email') { | |
if ( $w > $h ) { // landscape | |
$output = '/assets/snippets/thumb/phpThumb.php?src=' . $image . '&w=' . $width; | |
} elseif ( $w < $h ) { // portrait | |
$output = '/assets/snippets/thumb/phpThumb.php?src=' . $image . '&w=' . $width / 2.1; | |
} else { // square | |
$output = '/assets/snippets/thumb/phpThumb.php?src=' . $image . '&w=' . $width; | |
} | |
} elseif ($mode == 'w') { | |
return $w; | |
} elseif ($mode == 'h') { | |
return $h; | |
} | |
return $output; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment