cvs: gd /libgd/examples copyrotated.c

From: Date: Thu, 28 Feb 2008 09:49:52 +0000
Subject: cvs: gd /libgd/examples copyrotated.c
Groups: php.gd.cvs 
Request: Send a blank email to php-gd-cvs+get-436@lists.php.net to get a copy of this message
pajoye Thu Feb 28 09:49:52 2008 UTC Modified files: /gd/libgd/examples copyrotated.c Log: - don't double convert to radian http://cvs.php.net/viewvc.cgi/gd/libgd/examples/copyrotated.c?r1=1.1&r2=1.2&diff_format=u Index: gd/libgd/examples/copyrotated.c diff -u gd/libgd/examples/copyrotated.c:1.1 gd/libgd/examples/copyrotated.c:1.2 --- gd/libgd/examples/copyrotated.c:1.1 Thu Feb 28 00:03:59 2008 +++ gd/libgd/examples/copyrotated.c Thu Feb 28 09:49:52 2008 @@ -1,4 +1,4 @@ -/* $Id: copyrotated.c,v 1.1 2008/02/28 00:03:59 pajoye Exp $ */ +/* $Id: copyrotated.c,v 1.2 2008/02/28 09:49:52 pajoye Exp $ */ #include "gd.h" #include <stdio.h> #include <stdlib.h> @@ -38,7 +38,7 @@ { gdImagePtr im, im2; int new_width, new_height; - double angle; + double angle, a2; if (argc < 3) { fprintf(stderr, "Usage: copyrotated [angle in degree] [filename.png]\n"); @@ -55,12 +55,16 @@ /* cos adj hyp (cos = adjacent / hypothenus) sin op hyp (sin adjacent / hypothenus) + + 10 pixels margin */ - new_width = cos(angle * .0174532925) * gdImageSX(im) - - sin(angle * .0174532925) * gdImageSY(im) + 1; - new_height = - sin(angle * .0174532925) * gdImageSX(im) - + cos(angle * .0174532925) * gdImageSY(im) + 1; + /* to radian */ + a2 = angle * .0174532925; + + new_width = ceil(cos(a2) * gdImageSX(im)) + + fabs(sin(a2) * gdImageSY(im)); + new_height = ceil(cos(a2) * gdImageSY(im)) + + fabs(sin(a2) * gdImageSX(im)); im2 = gdImageCreateTrueColor(new_width, new_height); @@ -70,7 +74,11 @@ return 1; } + gdImageAlphaBlending(im2, 0); + gdImageFilledRectangle(im2, 0, 0, gdImageSX(im2), gdImageSY(im2), gdTrueColorAlpha(127,0,0,127)); + gdImageCopyRotated(im2, im, new_width/2, new_height/2, 0, 0, gdImageSX(im), gdImageSY(im), angle); + gdImageSaveAlpha(im2, 1); if (!savePngImage(im2, "rotated.png")) { fprintf(stderr, "Can't save PNG file rotated.png"); gdImageDestroy(im);

« previous php.gd.cvs (#436) next »