• Resolved veggie_89

    (@veggie_89)


    Hey, I’d like to use this plugin to set my focal point for background images, and then output the vertical and horizontal focal point percentages on my images in my theme files using inline css and php. Anyway to grab these values from the database for an image using php? Thanks!
    – Reggie

Viewing 1 replies (of 1 total)
  • Thread Starter veggie_89

    (@veggie_89)

    I took a look at the plugin code and found the answer to my question. For anyone else who’s looking:

    $focus  = get_post_meta( $post->ID, '_wpsmartcrop_image_focus', true );
    				if( !$focus || !is_array( $focus ) || !isset( $focus['left'] ) || !isset( $focus['top'] ) ) {
    					$focus = array(
    						'left' => '50',
    						'top'  => '50'
    					);
    					$default_focus = apply_filters( 'wpsmartcrop_default_focus', array(50, 50), $post->ID );
    					if( count( $default_focus ) > 1 ) {
    						$focus = array(
    							'left' => $default_focus[0],
    							'top'  => $default_focus[1]
    						);
    					}
    				}

    Note that you’ll probably need to replace: $post->ID, with the appropriate code to grab the ID of the image you’re displaying.

    You can then output this as css like this:
    style="background-position: <?php echo $focus[Left].'% '.$focus[top].'%';?>"

Viewing 1 replies (of 1 total)
  • The topic ‘Access focal point percentages via PHP?’ is closed to new replies.