note 48693 added to function.imagecopy

From: Date: Wed, 05 Jan 2005 03:30:23 +0000
Subject: note 48693 added to function.imagecopy
Groups: php.notes 
Request: Send a blank email to php-notes+get-82726@lists.php.net to get a copy of this message
I got some comments to Mirror() function given below by lecoguic at yahoo dot fr. First, it's quite good example of coding-without-bit-of-design approach ;) Lecoguic loops by all pixels and copy it each by each. Not good. The *only* reason I could find this approach explained is that he wanted MIRROR_BOTH to be handled. So the code looks quite ok, but performs quite poor. Below is much faster flipping function, blitting whole strips at once so it much more faster. $imgsrc is imagehandle. Function returns image handle to newly created flipped image. define("IMAGE_FLIP_HORIZONTAL", 1); define("IMAGE_FLIP_VERTICAL", 2); define("IMAGE_FLIP_BOTH", 3); function ImageFlip($imgsrc, $type) { $width = imagesx($imgsrc); $height = imagesy($imgsrc); $imgdest = imagecreatetruecolor($width, $height); switch( $type ) { // mirror wzgl. osi case IMAGE_FLIP_HORIZONTAL: for( $y=0 ; $y<$height ; $y++ ) imagecopy($imgdest, $imgsrc, 0, $height-$y-1, 0, $y, $width, 1); break; case IMAGE_FLIP_VERTICAL: for( $x=0 ; $x<$width ; $x++ ) imagecopy($imgdest, $imgsrc, $width-$x-1, 0, $x, 0, 1, $height); break; case IMAGE_FLIP_BOTH: for( $x=0 ; $x<$width ; $x++ ) imagecopy($imgdest, $imgsrc, $width-$x-1, 0, $x, 0, 1, $height); $rowBuffer = imagecreatetruecolor($width, 1); for( $y=0 ; $y<($height/2) ; $y++ ) { imagecopy($rowBuffer, $imgdest , 0, 0, 0, $height-$y-1, $width, 1); imagecopy($imgdest , $imgdest , 0, $height-$y-1, 0, $y, $width, 1); imagecopy($imgdest , $rowBuffer, 0, $y, 0, 0, $width, 1); } imagedestroy( $rowBuffer ); break; } return( $imgdest ); } ---- Manual Page -- http://www.php.net/manual/en/function.imagecopy.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48693 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48693&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48693&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48693&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48693&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48693&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48693&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48693&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82726) next »