Annotation of embedaddon/php/ext/gd/tests/gif.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: gif in/out
! 3: --SKIPIF--
! 4: <?php
! 5: // $Id: gif.phpt 222747 2006-11-03 14:51:02Z bjori $
! 6: if (!extension_loaded('gd')) {
! 7: die("skip gd extension not available.");
! 8: }
! 9: if (!function_exists("imagegif") || !function_exists("imagecreatefromgif") || !function_exists('imagecreatefromjpeg')) {
! 10: die("skip gif support unavailable");
! 11: }
! 12: ?>
! 13: --FILE--
! 14: <?php
! 15:
! 16: function check_box($r,$g,$b, $error=0) {
! 17: $cwd = dirname(__FILE__);
! 18: $im2 = imagecreatefromgif($cwd . '/test_gif.gif');
! 19:
! 20: $c = imagecolorsforindex($im2, imagecolorat($im2, 8,8));
! 21:
! 22: if ($error>0) {
! 23: $r_min = $r - $error; $r_max = $r + $error;
! 24: $g_min = $g - $error; $g_max = $g + $error;
! 25: $b_min = $b - $error; $b_max = $b + $error;
! 26:
! 27: if (
! 28: ($c['red'] >= $r_min || $c['red'] <= $r_max)
! 29: &&
! 30: ($c['green'] >= $g_min || $c['green'] <= $g_max)
! 31: &&
! 32: ($c['blue'] >= $b_min || $c['blue'] <= $b_max)
! 33: ) {
! 34: return true;
! 35: } else {
! 36: return false;
! 37: }
! 38: } else {
! 39: if ($c['red']==$r && $c['green']==$g && $c['blue']==$b) {
! 40: return true;
! 41: } else {
! 42: return false;
! 43: }
! 44: }
! 45: }
! 46: $cwd = dirname(__FILE__);
! 47:
! 48: $im = imagecreate(10,10);
! 49: $c = imagecolorallocate($im, 255,255,255);
! 50: imagefilledrectangle($im, 5,5, 10,10, $c);
! 51: imagegif($im, $cwd . '/test_gif.gif');
! 52: if (check_box(255,255,255)) {
! 53: echo "<4 cols: ok\n";
! 54: }
! 55:
! 56: $im = imagecreate(10,10);
! 57: for ($i=0; $i<7; $i++) {
! 58: $c = imagecolorallocate($im, $i,$i,$i);
! 59: }
! 60: imagefilledrectangle($im, 5,5, 10,10, $c);
! 61: imagegif($im, $cwd . '/test_gif.gif');
! 62: $i--;
! 63: if (check_box($i,$i,$i)) {
! 64: echo "<8 cols: ok\n";
! 65: }
! 66:
! 67:
! 68: $im = imagecreate(10,10);
! 69: for ($i=0; $i<15; $i++) {
! 70: $c = imagecolorallocate($im, $i,$i,$i);
! 71: }
! 72: imagefilledrectangle($im, 5,5, 10,10, $c);
! 73: imagegif($im, $cwd . '/test_gif.gif');
! 74: $i--;
! 75: if (check_box($i,$i,$i)) {
! 76: echo "<16 cols: ok\n";
! 77: }
! 78:
! 79:
! 80: $im = imagecreate(10,10);
! 81: for ($i=0; $i<31; $i++) {
! 82: $c = imagecolorallocate($im, $i,$i,$i);
! 83: }
! 84: imagefilledrectangle($im, 5,5, 10,10, $c);
! 85: imagegif($im, $cwd . '/test_gif.gif');
! 86: $i--;
! 87: if (check_box($i,$i,$i)) {
! 88: echo "<32 cols: ok\n";
! 89: }
! 90:
! 91:
! 92: $im = imagecreate(10,10);
! 93: for ($i=0; $i<63; $i++) {
! 94: $c = imagecolorallocate($im, $i,$i,$i);
! 95: }
! 96: imagefilledrectangle($im, 5,5, 10,10, $c);
! 97: imagegif($im, $cwd . '/test_gif.gif');
! 98: $i--;
! 99: if (check_box($i,$i,$i)) {
! 100: echo "<64 cols: ok\n";
! 101: }
! 102:
! 103: $im = imagecreate(10,10);
! 104: for ($i=0; $i<127; $i++) {
! 105: $c = imagecolorallocate($im, $i,$i,$i);
! 106: }
! 107: imagefilledrectangle($im, 5,5, 10,10, $c);
! 108: imagegif($im, $cwd . '/test_gif.gif');
! 109: $i--;
! 110: if (check_box($i,$i,$i)) {
! 111: echo "<128 cols: ok\n";
! 112: }
! 113:
! 114: $im = imagecreate(10,10);
! 115: for ($i=0; $i<255; $i++) {
! 116: $c = imagecolorallocate($im, $i,$i,$i);
! 117: }
! 118: imagefilledrectangle($im, 5,5, 10,10, $c);
! 119: imagegif($im, $cwd . '/test_gif.gif');
! 120: $i--;
! 121: if (check_box($i,$i,$i)) {
! 122: echo "<256 cols: ok\n";
! 123: }
! 124:
! 125:
! 126: $im = imagecreatefromjpeg($cwd . '/conv_test.jpeg');
! 127: imagefilledrectangle($im, 5,5, 10,10, 0xffffff);
! 128: imagegif($im, $cwd . '/test_gif.gif');
! 129: imagegif($im, $cwd . '/test_gif_2.gif');
! 130:
! 131: if (check_box(255,255,255, 10)) {
! 132: echo ">256 cols: ok\n";
! 133: }
! 134:
! 135: @unlink($cwd . "/test_gif.gif");
! 136: @unlink($cwd . "/test_gif_2.gif");
! 137: ?>
! 138: --EXPECT--
! 139: <4 cols: ok
! 140: <8 cols: ok
! 141: <16 cols: ok
! 142: <32 cols: ok
! 143: <64 cols: ok
! 144: <128 cols: ok
! 145: <256 cols: ok
! 146: >256 cols: ok
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>