Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chucktrukk/502970 to your computer and use it in GitHub Desktop.
Save chucktrukk/502970 to your computer and use it in GitHub Desktop.
<?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 . '&amp;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 . '&amp;w=' . $width;
} elseif ( $w < $h ) { // portrait
$output = '/assets/snippets/thumb/phpThumb.php?src=' . $image . '&amp;w=' . $width / 2.1;
} else { // square
$output = '/assets/snippets/thumb/phpThumb.php?src=' . $image . '&amp;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