Skip to content

Commit 673e7c3

Browse files
committed
ext/gd: adding imagecopyrotated.
copying an image area from a defined center position with an angle.
1 parent 14a868b commit 673e7c3

File tree

5 files changed

+88
-1
lines changed

5 files changed

+88
-1
lines changed

ext/gd/config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ AC_DEFUN([PHP_GD_CHECK_VERSION],[
149149
PHP_CHECK_LIBRARY(gd, gdImageStringFT, [AC_DEFINE(HAVE_GD_FREETYPE, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
150150
PHP_CHECK_LIBRARY(gd, gdVersionString, [AC_DEFINE(HAVE_GD_LIBVERSION, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
151151
PHP_CHECK_LIBRARY(gd, gdImageGetInterpolationMethod, [AC_DEFINE(HAVE_GD_GET_INTERPOLATION, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
152+
PHP_CHECK_LIBRARY(gd, gdImageCopyRotated, [AC_DEFINE(HAVE_GD_COPY_ROTATED, 1, [ ])], [], [ $GD_SHARED_LIBADD ])
152153
])
153154

154155
dnl

ext/gd/gd.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,34 @@ PHP_FUNCTION(imagecopyresampled)
10551055
}
10561056
/* }}} */
10571057

1058+
#if defined(HAVE_GD_COPY_ROTATED)
1059+
PHP_FUNCTION(imagecopyrotated)
1060+
{
1061+
zval *SIM, *DIM;
1062+
zend_long SX, SY, SW, SH, A;
1063+
gdImagePtr im_dst, im_src;
1064+
int srcH, srcW, srcY, srcX, angle;
1065+
double dstX, dstY;
1066+
1067+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "OOddlllll", &DIM, gd_image_ce, &SIM, gd_image_ce, &dstX, &dstY, &SX, &SY, &SW, &SH, &A) == FAILURE) {
1068+
RETURN_THROWS();
1069+
}
1070+
1071+
im_dst = php_gd_libgdimageptr_from_zval_p(DIM);
1072+
im_src = php_gd_libgdimageptr_from_zval_p(SIM);
1073+
1074+
srcX = SX;
1075+
srcY = SY;
1076+
srcH = SH;
1077+
srcW = SW;
1078+
angle = A;
1079+
1080+
gdImageCopyRotated(im_dst, im_src, dstX, dstY, srcX, srcY, srcW, srcH, angle);
1081+
RETURN_TRUE;
1082+
}
1083+
#endif
1084+
1085+
10581086
#ifdef PHP_WIN32
10591087
/* {{{ Grab a window or its client area using a windows handle (HWND property in COM instance) */
10601088
PHP_FUNCTION(imagegrabwindow)

ext/gd/gd.stub.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,10 @@ function imagecolorexactalpha(GdImage $image, int $red, int $green, int $blue, i
520520

521521
function imagecopyresampled(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_width, int $dst_height, int $src_width, int $src_height): bool {}
522522

523+
#ifdef HAVE_GD_COPY_ROTATED
524+
function imagecopyrotated(GdImage $dst_image, GdImage $src_image, int $dst_x, int $dst_y, int $src_x, int $src_y, int $dst_width, int $dst_height, int $src_width, int $src_height, int $angle): bool {}
525+
#endif
526+
523527
#ifdef PHP_WIN32
524528

525529
/** @refcount 1 */

ext/gd/gd_arginfo.h

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/gd/tests/copyrotated.phpt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
imagecopyrotated
3+
--EXTENSIONS--
4+
gd
5+
--SKIPIF--
6+
<?php
7+
if (!function_exists("imagecopyrotated")) die("skip requires imagecopyrotated");
8+
?>
9+
--FILE--
10+
<?php
11+
12+
$src_tc = imagecreatetruecolor(5,5);
13+
imagefill($src_tc, 0,0, 0x000000);
14+
imagesetpixel($src_tc, 1, 2, 0x0000ff);
15+
imagesetpixel($src_tc, 2, 2, 0xffffff);
16+
imagesetpixel($src_tc, 3, 2, 0xff0000);
17+
18+
19+
$dst_tc = imagecreatetruecolor(5,5);
20+
imagecopyrotated($dst_tc, $src_tc, 3,3, 0,0, imagesx($src_tc), imagesy($src_tc), 180);
21+
$p1 = imagecolorat($dst_tc, 1, 2) == imagecolorat($src_tc, 3, 2);
22+
$p2 = imagecolorat($dst_tc, 2, 2) == imagecolorat($src_tc, 2, 2);
23+
$p3 = imagecolorat($dst_tc, 3, 2) == imagecolorat($src_tc, 1, 2);
24+
25+
if ($p1 && $p2 && $p3) {
26+
echo "TC/TC: ok\n";
27+
}
28+
29+
imagedestroy($src_tc); imagedestroy($dst_tc);
30+
?>
31+
--EXPECT--
32+
TC/TC: ok

0 commit comments

Comments
 (0)