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 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()); }
function testBackgroundFillOnTransparentImage() { $path = dirname(__FILE__) . '/images/transparent.png'; // check the iamge is transparent $this->assertImageAlphaAtPoint($path, array(0, 0), 127); $image = new WP_Thumb($path, 'width=400&height=100&crop=1&background_fill=auto&cache=0&return=path'); $file = $image->returnImage(); $this->assertImageAlphaAtPoint($file, array(0, 0), 127); }
function testCropFromTopCenterWithResize() { // 20x10 image $path = dirname(__FILE__) . '/images/boxed-rectangle.png'; $image = new WP_Thumb($path, array('width' => 10, 'height' => 4, 'cache' => false, 'return' => 'path', 'crop' => true, 'crop_from_position' => 'center,center', 'resize' => true)); $file = $image->returnImage(); $this->assertImageRGBAtPoint($file, array(0, 0), array(255, 255, 255)); $this->assertImageRGBAtPoint($file, array(0, 1), array(255, 255, 255)); $this->assertImageRGBAtPoint($file, array(9, 0), array(255, 255, 255)); $this->assertImageRGBAtPoint($file, array(9, 1), array(255, 255, 255)); $this->assertImageRGBAtPoint($file, array(1, 1), array(0, 0, 0)); }
function testCropLargerThanSingleDimention() { $path = dirname(__FILE__) . '/images/google.png'; list($width, $height) = getimagesize($path); $this->assertNotNull($width); $this->assertNotNull($height); $image = new WP_Thumb($path, "width=200&height=300&crop=1&resize=0&cache=0&return=path"); $file = $image->returnImage(); $this->assertContains('/cache/', $file); $this->assertContains(WP_CONTENT_DIR, $file); list($new_width, $new_height) = getimagesize($file); $this->assertEquals($new_width, 200, 'Width is not expected'); $this->assertEquals($new_height, $height, 'Height is not expcted'); }
function testResizeProportionalLargeThanSourceImage() { $path = dirname(__FILE__) . '/images/google.png'; list($width, $height) = getimagesize($path); $this->assertNotNull($width); $this->assertNotNull($height); $width = $width * 2; $image = new WP_Thumb($path, "width={$width}&crop=0&cache=0&return=path"); $file = $image->returnImage(); $this->assertContains('/cache/', $file); $this->assertContains(WP_CONTENT_DIR, $file); list($new_width, $new_height) = getimagesize($file); $this->assertEquals($new_width, $width / 2, 'Width is not expected'); $this->assertEquals($new_height, floor($height), 'Height is not expected'); }
function testBackgroundFillOnWhiteImage() { $path = dirname(__FILE__) . '/images/google.png'; list($width, $height) = getimagesize($path); $this->assertNotNull($width); $this->assertNotNull($height); $image = new WP_Thumb($path, "width=100&height=100&cache=0&return=path&background_fill=255255255"); $file = $image->returnImage(); $this->assertContains('/cache/', $file); $this->assertContains(WP_CONTENT_DIR, $file); list($new_width, $new_height) = getimagesize($file); $this->assertEquals($new_width, 100, 'Width is not expected'); $this->assertEquals($new_height, 100, 'Height is not expcted'); $this->assertImageRGBAtPoint($file, array(1, 1), array(255, 255, 255)); }
private static function uploadDir() { if (empty(self::$wp_upload_dir)) { self::$wp_upload_dir = wp_upload_dir(); } return self::$wp_upload_dir; }
/** * Clear the internally cached upload dir. WP Thumb cached the results of wp_upload_dir() * for performance, however it's sometimes necessary to clear the internal cache, such as switching * blogs in multisite */ public static function clearUploadDirCache() { self::$wp_upload_dir = null; }
function testFileNameWithUppercaseFileName() { $path = dirname(__FILE__) . '/images/UpperCase.png'; $image = new WP_Thumb($path, array('width' => 10, 'height' => 10)); $this->assertTrue(file_exists($image->getCacheFilePath())); }
function testWatermarkPostResize() { // 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' => 10, 'height' => 10, 'cache' => false, 'return' => 'path', 'watermark_options' => array('mask' => $white, 'position' => 'top,left', 'padding' => 0, 'pre_resize' => false))); $file = $image->returnImage(); $this->assertImageRGBAtPoint($file, array(0, 0), array(255, 255, 255)); $this->assertImageRGBAtPoint($file, array(9, 9), array(255, 255, 255)); }