image rotate script?

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
sohlinux
Forum Newbie
Posts: 1
Joined: Fri Nov 21, 2008 8:07 pm

image rotate script?

Post by sohlinux »

Hello,

Does any know where I can get a php script to select and rotate multiple images?

I have loads of folders of images on my server , only some of the images need to be rotated so I need to be able to select only the images which need rotating rather than rotating all the images in the folder.

The images need to rotated either right or left and permanently without losing any quality.

Also I would need to be able to change folders.

Thanks
Tom
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Re: image rotate script?

Post by malcolmboston »

Im not sure on your skill level as you only have the 1 post, however this is really a rather trivial script to write, if your looking at learning PHP then this is actually a fairly decent start as it deals with file and array functions, 2 of the most heavily used (and problematic for newbies) area's of PHP.

heres a non-tested, copied and pasted example that will do only one directory, it could be simplified but.....

Code: Select all

 
<?php
 
$imgArray = array ();
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            $imgArray[] = $file;
        }
    }
    closedir($handle);
}
$randomItem = array_rand ($imgArray);
$randomImage = $imgArray[$randomItem];
?>
 
 
edit: its worth pointing out that this gets all files (minus . & .. files) in a directory, regardless if they're an image or not, an additional conditional (if / else) clause will be required to determine whether it is a image or not, again this is trivial so i will leave it to you.....
Post Reply