Skip to content

Instantly share code, notes, and snippets.

@davidsword
Last active February 3, 2018 03:05
Show Gist options
  • Save davidsword/1f3bcf36b4d161ecd0f4cde483c2e4d4 to your computer and use it in GitHub Desktop.
Save davidsword/1f3bcf36b4d161ecd0f4cde483c2e4d4 to your computer and use it in GitHub Desktop.
<?
function handsomefox_get_thumbnail($image_url, $size = 'thumbnail') {
$size = (in_array($size,array('thumbnail','medium','large','full')))
? strtolower($size) : 'thumbnail';
if ($size == 'full')
return $image_url;
//break down the file url string
$ext = pathinfo($image_url, PATHINFO_EXTENSION);
$file = str_replace('.'.$ext,'',$image_url);
$ext = strtolower($ext);
//get the ap width height
$width = get_option($size.'_size_w');
$height = get_option($size.'_size_h');
//replace "jpeg" w wordpress "jpg"
$ext = ($ext == 'jpeg') ? 'jpg': $ext;
//reconstruct url
$thumb = "{$file}-{$width}x{$height}.{$ext}";
return $thumb;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment