Ejemplo n.º 1
0
 function testDefaultImageInFilePath()
 {
     $file_path = realpath(ABSPATH . 'foo.png');
     $default = dirname(__FILE__) . '/images/google.png';
     $thumb = new WP_Thumb($file_path, array('default' => $default, 'width' => 20, 'height' => 20));
     $this->assertEquals($thumb->getFilePath(), $default);
     $this->assertFalse($thumb->errored());
 }
 function testResizeRemote404Image()
 {
     // Image is 275x95
     $url = 'http://www.google.com/intl/en_com/images/srpr/logoawd3w.png';
     $image = new WP_Thumb($url, "crop=1&return=path&width=80&height=80&cache=0");
     $file = $image->returnImage();
     $this->assertEquals($url, $file);
     $this->assertTrue($image->errored());
 }
Ejemplo n.º 3
0
 function testWatermarkTopLeft()
 {
     // black 100 x 100 image
     $path = dirname(__FILE__) . '/images/black.png';
     $white = dirname(__FILE__) . '/images/white-10.png';
     $image = new WP_Thumb($path, array('width' => 100, 'height' => 100, 'cache' => false, 'return' => 'path', 'watermark_options' => array('mask' => $white, 'position' => 'top,left', 'padding' => 0)));
     $file = $image->returnImage();
     $this->assertFalse($image->errored());
     $this->assertImageRGBAtPoint($file, array(0, 0), array(255, 255, 255));
     $this->assertImageRGBAtPoint($file, array(10, 0), array(0, 0, 0));
     $this->assertImageRGBAtPoint($file, array(0, 10), array(0, 0, 0));
 }
Ejemplo n.º 4
0
/**
 * Hook WP Thumb into the WordPress image functions
 *
 * Usage `the_post_thumbnail( 'width=100&height=200&crop=1' );`
 *
 * @param null  $null
 * @param int   $id
 * @param array $args
 * @return null
 */
function wpthumb_post_image($null, $id, $args)
{
    // check if $args is a WP Thumb argument list, or native WordPress one
    // wp thumb looks like this: 'width=300&height=120&crop=1'
    // native looks like 'thumbnail'
    if (is_string($args) && !strpos((string) $args, '=')) {
        $original_args = $args;
        if ($original_args === ($args = apply_filters('wpthumb_create_args_from_size', $args))) {
            return $null;
        }
    }
    $args = wp_parse_args($args);
    if (!empty($args[0])) {
        $args['width'] = $args[0];
    }
    if (!empty($args[1])) {
        $args['height'] = $args[1];
    }
    if (!empty($args['crop']) && $args['crop'] && empty($args['crop_from_position'])) {
        $args['crop_from_position'] = get_post_meta($id, 'wpthumb_crop_pos', true);
    }
    if (empty($path)) {
        $path = get_attached_file($id);
    }
    $path = apply_filters('wpthumb_post_image_path', $path, $id, $args);
    $args = apply_filters('wpthumb_post_image_args', $args, $id);
    $image = new WP_Thumb($path, $args);
    $args = $image->getArgs();
    extract($args);
    if (!$image->errored()) {
        $image_src = $image->returnImage();
        $crop = (bool) empty($crop) ? false : $crop;
        if (!$image->errored() && ($image_meta = @getimagesize($image->getCacheFilePath()))) {
            $html_width = $image_meta[0];
            $html_height = $image_meta[1];
        } else {
            $html_width = $html_height = false;
        }
    } else {
        $html_width = $width;
        $html_height = $height;
        $image_src = $image->getFileURL();
    }
    return array($image_src, $html_width, $html_height, true);
}
 function testNonExistingLocalPath()
 {
     $path = '/foo/bar.jpg';
     $image = new WP_Thumb($path, array('width' => 10, 'height' => 10));
     $this->assertTrue($image->errored());
 }
Ejemplo n.º 6
0
/**
 * Hook WP Thumb into the WordPress image functions
 *
 * Usage `the_post_thumbnail( 'width=100&height=200&crop=1' );`
 *
 * @param null $null
 * @param int $id
 * @param array $args
 * @return null
 */
function wpthumb_post_image($null, $id, $args)
{
    // check if $args is a WP Thumb argument list, or native WordPress one
    // wp thumb looks like this: 'width=300&height=120&crop=1'
    // native looks like 'thumbnail'...|array( 300, 300 )
    if (is_string($args) && !strpos((string) $args, '=')) {
        global $_wp_additional_image_sizes;
        // Convert keyword sizes to heights & widths.
        if ($args == 'thumbnail') {
            $new_args = array('width' => get_option('thumbnail_size_w'), 'height' => get_option('thumbnail_size_h'), 'crop' => get_option('thumbnail_crop'));
        } elseif ($args == 'medium') {
            $new_args = array('width' => get_option('medium_size_w'), 'height' => get_option('medium_size_h'));
        } elseif ($args == 'large') {
            $new_args = array('width' => get_option('large_size_w'), 'height' => get_option('large_size_h'));
        } elseif (!empty($_wp_additional_image_sizes) && array_key_exists($args, $_wp_additional_image_sizes)) {
            $new_args = array('width' => $_wp_additional_image_sizes[$args]['width'], 'height' => $_wp_additional_image_sizes[$args]['height'], 'crop' => $_wp_additional_image_sizes[$args]['crop'], 'image_size' => $args);
        } elseif ($args != ($new_filter_args = apply_filters('wpthumb_create_args_from_size', $args))) {
            $new_args = $new_filter_args;
        } else {
            $new_args = null;
        }
        if (!$new_args) {
            return $null;
        }
        $args = $new_args;
    }
    $args = wp_parse_args($args);
    if (!empty($args[0])) {
        $args['width'] = $args[0];
    }
    if (!empty($args[1])) {
        $args['height'] = $args[1];
    }
    if (!empty($args['crop']) && $args['crop'] && empty($args['crop_from_position'])) {
        $args['crop_from_position'] = get_post_meta($id, 'wpthumb_crop_pos', true);
    }
    if (empty($path)) {
        $path = get_attached_file($id);
    }
    $path = apply_filters('wpthumb_post_image_path', $path, $id, $args);
    $args = apply_filters('wpthumb_post_image_args', $args, $id);
    $image = new WP_Thumb($path, $args);
    $args = $image->getArgs();
    extract($args);
    if (!$image->errored()) {
        $image_src = $image->returnImage();
        $crop = (bool) empty($crop) ? false : $crop;
        if (!$image->errored() && ($image_meta = @getimagesize($image->getCacheFilePath()))) {
            $html_width = $image_meta[0];
            $html_height = $image_meta[1];
        } else {
            $html_width = $html_height = false;
        }
    } else {
        $html_width = $width;
        $html_height = $height;
        $image_src = $image->getFileURL();
    }
    return array($image_src, $html_width, $html_height, true);
}