function testDifferentFileURLSWithSameArgs() { $url_1 = 'http://www.google.com/images/srpr/logo3w.png'; $image_1 = new WP_Thumb($url_1, "crop=1&return=path&width=80&height=80&cache=0"); $url_2 = 'http://www.google.co.uk/images/srpr/logo3w.png'; $image_2 = new WP_Thumb($url_2, "crop=1&return=path&width=80&height=80&cache=0"); $this->assertNotEquals($image_1->getCacheFilePath(), $image_2->getCacheFilePath()); }
/** * 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 testFileNameWithUppercaseFileName() { $path = dirname(__FILE__) . '/images/UpperCase.png'; $image = new WP_Thumb($path, array('width' => 10, 'height' => 10)); $this->assertTrue(file_exists($image->getCacheFilePath())); }
/** * 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); }