static function fit_image_url($src, $width, $height)
{
$width = (int) $width;
$height = (int) $height;
// Umm...
if ($width < 1 || $height < 1) {
return $src;
}
// See if we should bypass WordPress.com SaaS resizing
if (has_filter('jetpack_images_fit_image_url_override')) {
/**
* Filters the image URL used after dimensions are set by Photon.
*
* @since 3.3.0
*
* @param string $src Image URL.
* @param int $width Image width.
* @param int $width Image height.
*/
return apply_filters('jetpack_images_fit_image_url_override', $src, $width, $height);
}
// If WPCOM hosted image use native transformations
$img_host = parse_url($src, PHP_URL_HOST);
if ('.files.wordpress.com' == substr($img_host, -20)) {
return add_query_arg(array('w' => $width, 'h' => $height, 'crop' => 1), $src);
}
// Use Photon magic
if (function_exists('jetpack_photon_url')) {
return jetpack_photon_url($src, array('resize' => "{$width},{$height}"));
}
// Arg... no way to resize image using WordPress.com infrastructure!
return $src;
}