Пример #1
0
function the_image_url($return = null)
{
    global $post;
    $tag = get_post_meta($post->ID, 'image_url', true);
    if (!$tag) {
        image_setup($post->ID);
        $tag = get_post_meta($post->ID, 'image_url', true);
    }
    if ($return) {
        return $tag;
    }
    /*else*/
    echo $tag;
}
Пример #2
0
function base_color($post)
{
    $url = get_post_meta($post->ID, 'image_url', true);
    if (!$url) {
        image_setup($post->ID);
        $url = get_post_meta($post->ID, 'image_url', true);
    }
    // get the image name
    $imgname = trim($url);
    if (!$imgname) {
        return 'FFFFFF';
    }
    // create a working image
    $im = imagecreatefromjpeg($imgname);
    $height = imagesy($im);
    $top = $height - 400;
    $width = imagesx($im);
    // sample five points in the image, based on rule of thirds and center
    $rgb = array();
    $topy = round($height / 3);
    $bottomy = round($height / 3 * 2);
    $leftx = round($width / 3);
    $rightx = round($width / 3 * 2);
    $centery = round($height / 2);
    $centerx = round($width / 2);
    $rgb[1] = imagecolorat($im, $leftx, $topy);
    $rgb[2] = imagecolorat($im, $rightx, $topy);
    $rgb[3] = imagecolorat($im, $leftx, $bottomy);
    $rgb[4] = imagecolorat($im, $rightx, $bottomy);
    $rgb[5] = imagecolorat($im, $centerx, $centery);
    // extract each value for r, g, b
    $r = array();
    $g = array();
    $b = array();
    $hex = array();
    $ct = 0;
    $val = 50;
    // process points
    for ($i = 1; $i <= 5; $i++) {
        $r[$i] = $rgb[$i] >> 16 & 0xff;
        $g[$i] = $rgb[$i] >> 8 & 0xff;
        $b[$i] = $rgb[$i] & 0xff;
        // find darkest color
        $tmp = $r[$i] + $g[$i] + $b[$i];
        if ($tmp < $val) {
            $val = $tmp;
            $ct = $i;
        }
        $hex[$i] = rgbhex($r[$i], $g[$i], $b[$i]);
    }
    return $hex[3];
}