Closed Thread Icon

Topic awaiting preservation: Php image rotation help needed (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12528" title="Pages that link to Topic awaiting preservation: Php image rotation help needed (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Php image rotation help needed <span class="small">(Page 1 of 1)</span>\

 
Synthetic
Paranoid (IV) Inmate

From: under your rug,
Insane since: Jul 2001

posted posted 11-26-2002 17:22

Ok check this out for a sec...

I've got 2 images, "image1.jpg" & "image2.jpg" now say I want them to rotate by use of a php script.

I have this worked up to rotate them in a php script, renamed to "image.gif" so it can be called from http://site.com/image.gif

code:
<?php
$dh = opendir(".");
while (false !== ($file = readdir($dh)))
{
if (preg_match('/\.jpg$/i', $file) and $file != "image.gif")
{
$filelist[] = $file;
}
}

srand((double)microtime()*1000000);
$picnum = rand(0, sizeof($filelist) - 1);

header("Location: " . $filelist[$picnum]);

closedir($dh);
?>



And to get that .gif file parsed as a php script, I've added this to a .htaccess file

code:
<Files image.gif>
ForceType application/x-httpd-php
</Files>



The way mentioned above and then going to http://site.com/image.gif will keep the same file name but not rotate the image on refresh

So I tried, renaming the image.gif > image.jpg and using...

code:
<?php
$dh = opendir(".");
while (false !== ($file = readdir($dh)))
{
if (preg_match('/\.jpg$/i', $file) and $file != "image.jpg")
{
$filelist[] = $file;
}
}

srand((double)microtime()*1000000);
$picnum = rand(0, sizeof($filelist) - 1);

header("Location: " . $filelist[$picnum]);

closedir($dh);
?>



code:
<Files image.jpg>
ForceType application/x-httpd-php
</Files>



So now everything else that was for the .gif was changed to .jpg also, well then when I would goto http://site.com/image.jpg the image would more or less just re-direct to http://site.com/image1.jpg and then upon going to http://site.com/image.jpg again it would rotate to http://site.com/image2.jpg

So basicly the second method worked for the rotation part, but not in the file name staying the same like the other method did, which brings me here

I want the url in the address bar to remain the same and only rotate the image not redirect to another image, so basicly rotate the image but keep the same file name

*Any help is appreciated*



[This message has been edited by Synthetic (edited 11-26-2002).]

Lurch
Paranoid (IV) Inmate

From: Behind the Wheel
Insane since: Jan 2002

posted posted 11-26-2002 17:43

to keep the same file name, you could use the image gd...

code:
//select your image however you choose
$photo = "photo.jpg";


//don't forget error handling!

//now create an image for php to output (starting from the selected image)
$src = ImageCreateFromJpeg($photo);

//set the header, so this .php file is read as an image by the browser
header("Content-type: image/jpeg");

//output the image, then destroy it on the server side
ImageJpeg($src, null, -1);
ImageDestroy($src);



Using this method you will have a .php extension but your file name will always be the same. The step from this to creating watermarks on images is sooo easy too

--Lurch--

[This message has been edited by Lurch (edited 11-26-2002).]

[This message has been edited by Lurch (edited 11-26-2002).]

« BackwardsOnwards »

Show Forum Drop Down Menu