Ejemplo n.º 1
0
function ImageRotateRightAngle( $imgSrc, $angle )
{
	//source de cette fonction : http://www.developpez.net/forums/showthread.php?t=54169
	$angle = min( ( (int)(($angle+45) / 90) * 90), 270 );
	if( $angle == 0 )
	return( $imgSrc );
	$srcX = imagesx( $imgSrc );
	$srcY = imagesy( $imgSrc );

	switch( $angle )
	{
		case 90:
		$imgDest = imagecreatetruecolor( $srcY, $srcX );
		for( $x=0; $x<$srcX; $x++ )
		for( $y=0; $y<$srcY; $y++ )
		imagecopy($imgDest, $imgSrc, $srcY-$y-1, $x, $x, $y, 1, 1);
		break;

		case 180:
		$imgDest = ImageFlip( $imgSrc, IMAGE_FLIP_BOTH );
		break;

		case 270:
		$imgDest = imagecreatetruecolor( $srcY, $srcX );
		for( $x=0; $x<$srcX; $x++ )
		for( $y=0; $y<$srcY; $y++ )
		imagecopy($imgDest, $imgSrc, $y, $srcX-$x-1, $x, $y, 1, 1);
		break;
	}

		return( $imgDest );
}
Ejemplo n.º 2
0
function imageRotateBicubic($imgSrc, $angle)
{
    // ensuring we got really RightAngle (if not we choose the closest one)
    $angle = min((int) (($angle + 45) / 90) * 90, 270);
    // no need to fight
    if ($angle == 0) {
        return $imgSrc;
    }
    // dimenstion of source image
    $srcX = imagesx($imgSrc);
    $srcY = imagesy($imgSrc);
    switch ($angle) {
        case 90:
            $imgDest = imagecreatetruecolor($srcY, $srcX);
            for ($x = 0; $x < $srcX; $x++) {
                for ($y = 0; $y < $srcY; $y++) {
                    imagecopy($imgDest, $imgSrc, $srcY - $y - 1, $x, $x, $y, 1, 1);
                }
            }
            break;
        case 180:
            $imgDest = ImageFlip($imgSrc, IMAGE_FLIP_BOTH);
            break;
        case 270:
            $imgDest = imagecreatetruecolor($srcY, $srcX);
            for ($x = 0; $x < $srcX; $x++) {
                for ($y = 0; $y < $srcY; $y++) {
                    imagecopy($imgDest, $imgSrc, $srcY - $y - 1, $srcX - $x - 1, $x, $y, 1, 1);
                }
            }
            break;
    }
    return $imgDest;
}