note 43227 added to function.imagerotate

From: Date: Mon, 14 Jun 2004 21:08:44 +0000
Subject: note 43227 added to function.imagerotate
Groups: php.notes 
Request: Send a blank email to php-notes+get-71064@lists.php.net to get a copy of this message
Here comes a function wich *really* works with php 4.3.1 for 90°,180°, 270°. function rotate ( $pFile, $pAngle, $pDestFile ) { // remove all useless 360 degrees $pAngle = $pAngle % 360; // create an image ressource from $pFile $ImgIn = imagecreatefromjpeg ( $pFile ); // case of flip if ( $pAngle == 180 ) { $ImgOut = ImageRotate ( $ImgIn, $pAngle, 180 ); } else { // other cases (90 or 270°) $x = imagesx ( $ImgIn ); $y = imagesy ( $ImgIn ); $MaxXY = max ($x, $y); // prepare intermediate picture, full size in order to loose nothing $SquareImg = imagecreatetruecolor($MaxXY, $MaxXY); imagecopy($SquareImg, $ImgIn, 0, 0, 0, 0, $x, $y); $SquareImg = ImageRotate ( $SquareImg, $pAngle, 0 ); if ( $pAngle == 90 ) { // we are in 90° rotation $ImgOut = imagecreatetruecolor($y, $x); imagecopy ( $ImgOut, $SquareImg, 0, 0, 0, $MaxXY - $x, $y, $x ); } elseif ( $pAngle == 270 ) { // we are in 270° rotation $ImgOut = imagecreatetruecolor($y, $x); imagecopy ( $ImgOut, $SquareImg, 0, 0, $MaxXY-$y, 0, $y, $x ); } } ImageJPEG ( $ImgOut, $pDestFile ); } // exemple $FileIn = "/var/www/html/images/1.jpeg"; $FileOut = "/var/www/html/images/1.jpeg"; // the one to create rotate ( $FileIn, 90, $FileOut ); ---- Manual Page -- http://www.php.net/manual/en/function.imagerotate.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+43227 Delete -- http://master.php.net/manage/user-notes.php?action=delete+43227&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+43227&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#71064) next »