Exemple #1
0
/**
* Draw the time ticker below the video.  We need to draw the
* time, period and fraction separately so we can keep the period
* fixed in place and not have things move around.
* 
* @param mixed $test
* @param mixed $frameTime
* @param mixed $im
* @param mixed $rect
*/
function DrawFrameTime(&$test, $frameTime, $im, $rect)
{
    global $timeHeight, $backgroundColor, $timeFont, $textColor, $fps, $fractionTime;
    static $font_size = 0;
    static $ascent = 0;
    $updated = false;
    if (!$font_size) {
        $font_size = GetFontSize($rect['width'], $rect['height'], "000.00", $timeFont);
    }
    if (!$ascent && $font_size) {
        $box = imagettfbbox($font_size, 0, $timeFont, "12345678.90");
        $ascent = abs($box[7]);
    }
    if (!isset($test['periodRect'])) {
        $test['periodRect'] = array();
        $pos = CenterText($im, $rect['x'], $rect['y'], $rect['width'], $rect['height'], $font_size, "000.00", $timeFont, $ascent);
        $test['periodRect']['y'] = $pos['y'];
        $pos = CenterText($im, $rect['x'], $rect['y'], $rect['width'], $rect['height'], $font_size, '.', $timeFont, $ascent);
        $test['periodRect']['x'] = $pos['x'];
        $box = imagettfbbox($font_size, 0, $timeFont, '.');
        $test['periodRect']['width'] = abs($box[4] - $box[0]);
    }
    $seconds = floor($frameTime / 1000);
    $fraction = floor($frameTime / (1000 / $fractionTime)) % $fractionTime;
    if ($fractionTime == 100) {
        $fraction = sprintf("%02d", $fraction);
    } elseif ($fractionTime == 1000) {
        $fraction = sprintf("%03d", $fraction);
    }
    $time = "{$seconds}.{$fraction}";
    if (!isset($test['last_time']) || $test['last_time'] !== $time) {
        $updated = true;
        $test['last_time'] = $time;
        // erase the last time
        imagefilledrectangle($im, $rect['x'], $rect['y'], $rect['x'] + $rect['width'], $rect['y'] + $rect['height'], $backgroundColor);
        // draw the period
        imagettftext($im, $font_size, 0, $test['periodRect']['x'], $test['periodRect']['y'], $textColor, $timeFont, '.');
        // draw the seconds
        $box = imagettfbbox($font_size, 0, $timeFont, $seconds);
        $s_width = abs($box[4] - $box[0]);
        $box = imagettfbbox($font_size, 0, $timeFont, "{$seconds}.");
        $pad = abs($box[4] - $box[0]) - $s_width;
        imagettftext($im, $font_size, 0, $test['periodRect']['x'] + $test['periodRect']['width'] - $s_width - $pad, $test['periodRect']['y'], $textColor, $timeFont, $seconds);
        //draw the fraction
        $box = imagettfbbox($font_size, 0, $timeFont, $fraction);
        $t_width = abs($box[4] - $box[0]);
        $box = imagettfbbox($font_size, 0, $timeFont, ".{$fraction}");
        $pad = abs($box[4] - $box[0]) - $t_width + 1;
        imagettftext($im, $font_size, 0, $test['periodRect']['x'] + $pad, $test['periodRect']['y'], $textColor, $timeFont, $fraction);
    }
    return $updated;
}
Exemple #2
0
/**
* Draw the time ticker below the video.  We need to draw the
* time, period and fraction separately so we can keep the period
* fixed in place and not have things move around.
* 
* @param mixed $test
* @param mixed $frameTime
* @param mixed $im
* @param mixed $rect
*/
function DrawFrameTime(&$test, $frameTime, $im, $rect)
{
    global $timeHeight, $backgroundColor, $timeFont, $textColor, $fps, $fractionTime, $timeSeconds, $bgEvenText, $bgOddText, $stopTime, $stopText;
    static $font_size = 0;
    static $ascent = 0;
    $updated = false;
    $suffix = $timeSeconds ? 's' : '';
    if (!$font_size) {
        $font_size = GetFontSize($rect['width'], $rect['height'], "000.00", $timeFont);
    }
    if (!$ascent && $font_size) {
        $box = imagettfbbox($font_size, 0, $timeFont, "12345678.90");
        $ascent = abs($box[7]);
    }
    if (!isset($test['periodRect'])) {
        $test['periodRect'] = array();
        $pos = CenterText($im, $rect['x'], $rect['y'], $rect['width'], $rect['height'], $font_size, "000.00{$suffix}", $timeFont, $ascent, $rect['align']);
        $test['periodRect']['y'] = $pos['y'];
        $posText = $rect['align'] == 'right' ? ".00{$suffix}" : '.';
        $pos = CenterText($im, $rect['x'], $rect['y'], $rect['width'], $rect['height'], $font_size, $posText, $timeFont, $ascent, $rect['align']);
        $test['periodRect']['x'] = $pos['x'];
        $box = imagettfbbox($font_size, 0, $timeFont, '.');
        $test['periodRect']['width'] = abs($box[4] - $box[0]);
    }
    $seconds = floor($frameTime / 1000);
    $fraction = floor($frameTime / (1000 / $fractionTime)) % $fractionTime;
    if ($fractionTime == 100) {
        $fraction = sprintf("%02d", $fraction);
    } elseif ($fractionTime == 1000) {
        $fraction = sprintf("%03d", $fraction);
    }
    if (!isset($test['endText']) && isset($stopTime) && isset($test['pageData'][$test['run']][$test['cached']][$stopTime]) && $frameTime >= $test['pageData'][$test['run']][$test['cached']][$stopTime]) {
        $prefix = isset($stopText) ? "{$stopText} " : '';
        $test['endText'] = "{$prefix}{$seconds}.{$fraction}{$suffix}";
    }
    $time = isset($test['endText']) ? $test['endText'] : "{$seconds}.{$fraction}";
    if (!isset($test['last_time']) || $test['last_time'] !== $time) {
        $updated = true;
        $test['last_time'] = $time;
        // erase the last time
        $bgColor = $rect['even'] ? $bgEvenText : $bgOddText;
        imagefilledrectangle($im, $rect['x'], $rect['y'], $rect['x'] + $rect['width'], $rect['y'] + $rect['height'], $bgColor);
        if (isset($test['endText'])) {
            $pos = CenterText($im, $rect['x'], $rect['y'], $rect['width'], $rect['height'], $font_size, $test['endText'], $timeFont, $ascent, $rect['align']);
            if (isset($pos)) {
                imagettftext($im, $font_size, 0, $pos['x'], $pos['y'], $textColor, $timeFont, $test['endText']);
            }
        } else {
            // draw the period
            imagettftext($im, $font_size, 0, $test['periodRect']['x'], $test['periodRect']['y'], $textColor, $timeFont, '.');
            // draw the seconds
            $box = imagettfbbox($font_size, 0, $timeFont, $seconds);
            $s_width = abs($box[4] - $box[0]);
            $box = imagettfbbox($font_size, 0, $timeFont, "{$seconds}.");
            $pad = abs($box[4] - $box[0]) - $s_width;
            imagettftext($im, $font_size, 0, $test['periodRect']['x'] + $test['periodRect']['width'] - $s_width - $pad, $test['periodRect']['y'], $textColor, $timeFont, $seconds);
            //draw the fraction
            $box = imagettfbbox($font_size, 0, $timeFont, "{$fraction}{$suffix}");
            $t_width = abs($box[4] - $box[0]);
            $box = imagettfbbox($font_size, 0, $timeFont, ".{$fraction}{$suffix}");
            $pad = abs($box[4] - $box[0]) - $t_width + 1;
            imagettftext($im, $font_size, 0, $test['periodRect']['x'] + $pad, $test['periodRect']['y'], $textColor, $timeFont, "{$fraction}{$suffix}");
        }
    }
    return $updated;
}
        imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $black);
        $x = 0;
        foreach ($tests as $test) {
            if (substr($test['image'], -4) == '.png') {
                $frame = imagecreatefrompng($test['image']);
            } else {
                $frame = imagecreatefromjpeg($test['image']);
            }
            if (isset($frame) && $frame !== false) {
                $w = imagesx($frame);
                $h = imagesy($frame);
                imagecopy($im, $frame, $x, 0, 0, 0, $w, $h);
                imagedestroy($frame);
                unset($frame);
                $rect = $test['labelRect'];
                $pos = CenterText($im, $x + $textMargin, $textTop + $textMargin, $w - 2 * $textMargin, $textHeight - 2 * $textMargin, $fontSize, $test['label']);
                if (isset($pos)) {
                    imagettftext($im, $fontSize, 0, $pos['x'], $pos['y'], $textColor, $labelFont, $test['label']);
                }
                $x += $w + $spacing;
            }
        }
        header("Content-type: image/png");
        imagepng($im);
    } else {
        header("HTTP/1.0 404 Not Found");
    }
}
/**
* Parse the list of tests and identify the screen shots to compare
*