Determine if Jetpack is installed and can generate photon URLs:
function_exists( ‘jetpack_photon_url' );
Determine whether photon is an active Jetpack module:
class_exists( 'Jetpack' ) && method_exists( 'Jetpack', 'get_active_modules' ) && in_array( 'photon', Jetpack::get_active_modules() )
Example how to apply photon to any image you wish to load via custom theme:
echo apply_filters( 'jetpack_photon_url', get_template_directory_uri() . '/img/logo.png' );
Example with argument:
echo apply_filters( 'jetpack_photon_url', get_template_directory_uri() . '/img/logo.png', 'filter=grayscale', 'https' );
Set custom photon arguments for all photon urls:
/**
* Frontlane Studio Custom Photon Arguments.
*
* @access public
* @param mixed $args Photon Arguments.
*/
function flstudio_custom_photon( $args ) {
$args['quality'] = 80;
$args['strip'] = 'all';
$args['filter'] = 'grayscale';
return $args;
}
add_filter( 'jetpack_photon_pre_args', 'flstudio_custom_photon' );
Set header Image to use photon:
/**
* Frontlane Studio Photonize Header Image.
*
* @access public
* @param mixed $image Image.
*/
function flstudio_photonize_header_image( $image ) {
if ( $image && function_exists( 'jetpack_photon_url' ) ) {
$image = jetpack_photon_url( $image );
}
return $image;
}
add_filter( 'theme_mod_header_image', 'flstudio_photonize_header_image' );
Supported query arguments:
ParameterDescriptionUsagewwidth (px)w=50hheight (px)h=50cropcrop x,y,w,h (defaults to %)crop=5,10,20,40resizeresize and crop to given dimensions (px)resize=250,300fitkeep aspect ratio, but fit to within given box (px)fit=100,100lbadd letterboxing, color code is optional (it’s black by default)lb=300,250,1A4E9Fulbremove letterboxing (auto detects the letterbox color)ulb=truefilterapply various imagefilter() filtersfilter=grayscalebrightnessadjusts brightnessbrightness=100contrastadjusts contrastcontrast=50colorizeapplies a color huecolorize=255,0,0smoothsmoothes out the imagesmooth=2zoomsize images for high pixel ratio deviceszoom=2qualitysets the quality for JPEG imagesquality=50stripremoves metadata from JPEG imagesstrip=allSupported query arguments.