TestTimberImage::checkPixel PHP Method

checkPixel() public static method

public static checkPixel ( $file, $x, $y, $color = '#FFFFFF', $upper_color = false )
    public static function checkPixel($file, $x, $y, $color = '#FFFFFF', $upper_color = false)
    {
        if (self::is_png($file)) {
            $image = imagecreatefrompng($file);
        } else {
            if (self::is_gif($file)) {
                $image = imagecreatefromgif($file);
            } else {
                $image = imagecreatefromjpeg($file);
            }
        }
        $pixel_rgb = imagecolorat($image, $x, $y);
        $colors_of_file = imagecolorsforindex($image, $pixel_rgb);
        if ($upper_color) {
            $upper_colors = ImageOperation::hexrgb($upper_color);
        }
        $test_colors = ImageOperation::hexrgb($color);
        if (isset($upper_colors) && $upper_colors) {
            if (self::checkChannel('red', $test_colors, $colors_of_file, $upper_colors) && self::checkChannel('green', $test_colors, $colors_of_file, $upper_colors) && self::checkChannel('blue', $test_colors, $colors_of_file, $upper_colors)) {
                return true;
            }
            return false;
        }
        if ($test_colors['red'] === $colors_of_file['red'] && $test_colors['blue'] === $colors_of_file['blue'] && $test_colors['green'] === $colors_of_file['green']) {
            return true;
        }
        return false;
    }

Usage Example

 function testCropTopCenter()
 {
     $cropper = TestTimberImage::copyTestImage('cropper.png');
     $resized = TimberImageHelper::resize($cropper, 300, 100, 'top-center');
     $resized = str_replace('http://example.org', '', $resized);
     $resized = TimberUrlHelper::url_to_file_system($resized);
     $is_red = TestTimberImage::checkPixel($resized, 100, 50, '#ff0000', '#ff0800');
     $this->assertTrue($is_red);
 }
All Usage Examples Of TestTimberImage::checkPixel