note 58869 added to function.imagerotate
| From: | olav-xatvolvo-power dot net at osu1 dot php dot net | Date: | Fri, 18 Nov 2005 12:17:30 +0000 |
| Subject: | note 58869 added to function.imagerotate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-98753@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagerotate.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+58869
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+58869&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+58869&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+58869&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+58869&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+58869&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+58869&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+58869&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+58869&report=yes
Search -- http://master.php.net/manage/user-notes.php