note 58869 deleted from function.imagerotate by danbrown

From: Date: Tue, 02 Dec 2008 15:00:29 +0000
Subject: note 58869 deleted from function.imagerotate by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-147537@lists.php.net to get a copy of this message
Note Submitter: olav-x at volvo-power.net ---- I tried the example provided by 'jonathan AT sharpmedia DOT net', and that gave me strange rotations, with offset on the image. I dont need an advanced rotation script like that, so I used his function wrapper and make a more simple edition. ps. the code above the function is only for test-purpose. I'll retrieve srcpic from the db. the idea here, is that I'll store rotated thumbs of the original thumb. Then the user can click on the thumb which is "correctly rotated" and then the original file will be rotated. I think I'll make some backup function implemented too! the idea is that the rotated files will have _ROT<int>.ext eg. if you rotate the file "bicycle.jpg" 1 rotation (90 degrees), it will be copied to: bicycle_ROT1.jpg, 180 degrees would be _ROT2.jpg, and so on. There is only 3 rots, I should have removed the ROT0 here, as well as the code might need improvement. However, I think that simple codes like this ones, are the easiest ones to use as a foundation, as they are - simple! What you can improve, if you want to do this: * there is a lot! however, you have to wrap the $dst in something like: if (!isset($dst)) { } eg. so you can over-ride the "save to", when calling the function! this is beta 0.0000001 however, so play with it, slaughter it, whatever. good luck! Olav Alexander Mjelde <?php // #### start of test $srcpic = 'bilder/biler/_tmp/foo.jpg'; echo rotateImage($srcpic, $dstpic, 1, 100); echo rotateImage($srcpic, $dstpic, 2, 100); echo rotateImage($srcpic, $dstpic, 3, 100); // #### end of test // this function rotates an image function rotateImage($src, $dst, $count = 1, $quality = 95) { if (!file_exists($src)) { return false; } // generate output filename extension $dst = substr($src, 0, strrpos($src, ".")) . "_ROT" . $count . substr($src, strrpos($src, "."), strlen($src)); switch ($count) { case 0: $degrees = 0; break; case 1: $degrees = 90; break; case 2: $degrees = 180; break; case 3: $degrees = 270; break; } // Load $source = imagecreatefromjpeg($src); // Rotate $rotate = imagerotate($source, 360 - $degrees, 0); // Output imagejpeg($rotate, $dst, $quality); imageDestroy($rotate); imageDestroy($source); return true; } ?>

« previous php.notes (#147537) next »