Annotation of embedaddon/php/ext/gd/tests/copyresized.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: imagecopyresized
! 3: --SKIPIF--
! 4: <?php
! 5: if (!function_exists('imagecopyresized')) die("skip gd extension not available\n");
! 6: ?>
! 7: --FILE--
! 8: <?php
! 9:
! 10: function get_hexcolor($im, $c) {
! 11: if (imageistruecolor($im)) {
! 12: return $c;
! 13: }
! 14: $colors = imagecolorsforindex($im, $c);
! 15: return ($colors['red'] << 16) + ($colors['green'] << 8) + ($colors['blue']);
! 16: }
! 17:
! 18: function check_doublesize($dst) {
! 19: $im = imagecreatetruecolor(38,38);
! 20: imagefill($im,0,0, 0xffffff);
! 21: imagefilledrectangle($im, 0,0,9,9, 0xff0000);
! 22: imagefilledrectangle($im, 0,28,9,37, 0xff0000);
! 23: imagefilledrectangle($im, 28,0,37,9, 0xff0000);
! 24: imagefilledrectangle($im, 28,28,37,37, 0xff0000);
! 25: imagefilledrectangle($im, 14,14,23,23, 0xff0000);
! 26:
! 27: for ($x = 0; $x < 38; $x++) {
! 28: for ($y = 0; $y < 38; $y++) {
! 29: $p1 = imagecolorat($im, $x, $y);
! 30: $p2 = imagecolorat($dst, $x, $y);
! 31: if (get_hexcolor($im, $p1) != get_hexcolor($dst, $p2)) {
! 32: return false;
! 33: }
! 34: }
! 35: }
! 36: return true;
! 37: }
! 38:
! 39: $src_tc = imagecreatetruecolor(19,19);
! 40: imagefill($src_tc, 0,0, 0xffffff);
! 41: imagefilledrectangle($src_tc, 0,0,4,4, 0xff0000);
! 42: imagefilledrectangle($src_tc, 14,0,18,4, 0xff0000);
! 43: imagefilledrectangle($src_tc, 0,14,4,18, 0xff0000);
! 44: imagefilledrectangle($src_tc, 14,14,18,18, 0xff0000);
! 45: imagefilledrectangle($src_tc, 7,7,11,11, 0xff0000);
! 46:
! 47: $dst_tc = imagecreatetruecolor(38,38);
! 48: imagecopyresized($dst_tc, $src_tc, 0,0, 0,0, imagesx($dst_tc), imagesy($dst_tc), 19,19);
! 49:
! 50: if (!check_doublesize($dst_tc)) exit("1 failed\n");
! 51: echo "TC->TC: ok\n";
! 52:
! 53: $src_tc = imagecreate(19,19);
! 54: $white = imagecolorallocate($src_tc, 255,255,255);
! 55: $red = imagecolorallocate($src_tc, 255,0,0);
! 56:
! 57: imagefilledrectangle($src_tc, 0,0,4,4, $red);
! 58: imagefilledrectangle($src_tc, 14,0,18,4, $red);
! 59: imagefilledrectangle($src_tc, 0,14,4,18, $red);
! 60: imagefilledrectangle($src_tc, 14,14,18,18, $red);
! 61: imagefilledrectangle($src_tc, 7,7,11,11, $red);
! 62:
! 63: $dst_tc = imagecreatetruecolor(38,38);
! 64: imagecopyresized($dst_tc, $src_tc, 0,0, 0,0, imagesx($dst_tc), imagesy($dst_tc), 19,19);
! 65:
! 66: if (!check_doublesize($dst_tc)) exit("2 failed\n");
! 67: echo "P->TC: ok\n";
! 68:
! 69: $src_tc = imagecreate(19,19);
! 70: $white = imagecolorallocate($src_tc, 255,255,255);
! 71: $red = imagecolorallocate($src_tc, 255,0,0);
! 72:
! 73: imagefilledrectangle($src_tc, 0,0,4,4, $red);
! 74: imagefilledrectangle($src_tc, 14,0,18,4, $red);
! 75: imagefilledrectangle($src_tc, 0,14,4,18, $red);
! 76: imagefilledrectangle($src_tc, 14,14,18,18, $red);
! 77: imagefilledrectangle($src_tc, 7,7,11,11, $red);
! 78:
! 79: $dst_tc = imagecreate(38,38);
! 80: $white = imagecolorallocate($src_tc, 255,255,255);
! 81: $red = imagecolorallocate($src_tc, 255,0,0);
! 82:
! 83: imagecopyresized($dst_tc, $src_tc, 0,0, 0,0, imagesx($dst_tc), imagesy($dst_tc), 19,19);
! 84:
! 85: if (!check_doublesize($dst_tc)) exit("3 failed\n");
! 86: echo "P->P: ok\n";
! 87: ?>
! 88: --EXPECTF--
! 89: TC->TC: ok
! 90: P->TC: ok
! 91: P->P: ok
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>