PHP Random Image extension
I am trying to use the PHP random image generator but I don't
know where to specify the size I want all the pictures to come up
in the code. I created a "php" test page and inserted said code
where I want the images to display but they are too large and throw
the entire page off. Is there a way to tell it that all pictures
should be called up at 240(width) x 350(height)? Any help would be
greatly appreciated. The reason I am doing this is because there
are about 200 images (of students) in this folder and coding each
picture seperately is too time consuming.
Regards,
RM (using DW MX2004)
Disregard....I figured it out. As it turns out the best
solution would be to have your original pictures saved with the
desired dimensions. I was able to point the PHP to a directory that
contained pictures with said dimensions and it worked like a charm.
regards.
Similar Messages
-
Hello everyone,
Im trying to use (for the first time) random images generated
by PHP. I
installed a Technorama extension and then followed thru the
steps to place a
random image in the page, but there is nothing there when I
browse the page.
Please forgive my ignorance, but I have never done any php
stuff before.
And yes, the files are uploaded to my server. (which does
have php enabled).
The practice page I am using is
www.fionahayward.com/interiordesign/practice.php
I have the effect working with javascript on this page
www.fionahayward.com/interiordesign but am trying to use php
incase people
have javascript turned off.
Maybe its something to do with how Ive set up Server
Behaviours or something
(only guessing)
Thanks for listening
Fiona1) create a php file named rotate.php in the folder where the
images are.
2) paste this code (between the [code ] and [/code]
markers... into that file and save it.
[code]
<?php
$folder = '.';
$extList = array();
$extList['gif'] = 'image/gif';
$extList['jpg'] = 'image/jpeg';
$extList['jpeg'] = 'image/jpeg';
$extList['png'] = 'image/png';
// --------------------- END CONFIGURATION
$img = null;
if (substr($folder,-1) != '/') {
$folder = $folder.'/';
if (isset($_GET['img'])) {
$imageInfo = pathinfo($_GET['img']);
if (
isset( $extList[ strtolower( $imageInfo['extension'] ) ] )
file_exists( $folder.$imageInfo['basename'] )
$img = $folder.$imageInfo['basename'];
} else {
$fileList = array();
$handle = opendir($folder);
while ( false !== ( $file = readdir($handle) ) ) {
$file_info = pathinfo($file);
if (
isset( $extList[ strtolower( $file_info['extension'] ) ] )
$fileList[] = $file;
closedir($handle);
if (count($fileList) > 0) {
$imageNumber = time() % count($fileList);
$img = $folder.$fileList[$imageNumber];
if ($img!=null) {
$imageInfo = pathinfo($img);
$contentType = 'Content-type: '.$extList[
$imageInfo['extension'] ];
header ($contentType);
readfile($img);
} else {
if ( function_exists('imagecreate') ) {
header ("Content-type: image/png");
$im = @imagecreate (100, 100)
or die ("Cannot initialize new GD image stream");
$background_color = imagecolorallocate ($im, 255, 255, 255);
$text_color = imagecolorallocate ($im, 0,0,0);
imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color);
imagepng ($im);
imagedestroy($im);
?>
[/code]
4) in whichever file you want the random images to appear,
reference the image so:
src="path/to/that/image/folder/rotate.php"
I tend to use root-relative pathing, but that part is up to
you.
NOTE: I've found that random image references are quirky in
IE browsers - they seem to want the image width and height to
display images that are dynamically selected... I've used this
script to display images that are all the same size and groups that
aren't. When the image size is unknown, I use width:100%
height:100% in my css)
email me if you have any issues with using the script. I use
it a lot with WordPress sites, but it isn't a WP only solution.
syncbox AT gmail DOT com (do the obvious)
HTH -
Looking for a random image extension
Does anybody know of a good FREE extension that will put a
random image inside a cell of a table?
I'm actually looking to do two different things. The first: I
want a random image from about 10 images to change every time the
user reloads the page. The second: I want images from about 10
images to fade up, stay on the page for a few seconds, then fade
down and have another one of the 10 fade up, so on and so forth.
If anyone knows of a free extension that will do this, I
would love to know about it, thanks!This one works fine for me,
* Ultimate Fade-In Slideshow (v1.51): © Dynamic Drive (
http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit
http://www.dynamicdrive.com/
for this script and 100s more.
hth -
PHP Random Images (Mr. Powers or other PHP Experts)
Hello everyone,
This is the script from David Power's book using arrays and the rand function (Disclosure).
Basically it changes the images randomly on browser load or refresh.
However, I am trying to add an additional, not sure what to call it, a string or another caption for each images.
Instead of this being a caption, it will be a link, so a link will appear under each caption that goes to another page
when it is clicked on for additional info about the image.
I tried adding another caption and adding a like to it but getting syntax error.
Thanks everyone!
Here is the code:
<?php
$images = array(
array('file' => 'image1',
'caption' => 'Caption 1'),
array('file' => 'image2',
'caption' => 'Caption 2'),
$i = rand(0, count($images)-1);
$selectedImage = "graphics/{$images[$i]['file']}.png";
$caption = $images[$i]['caption'];
?>
And here is where the images are written to the page:
<div id="stage">
<img src="<?php echo $selectedImage; ?>" alt="Random image" />
<p id="caption"><?php echo $caption; ?></p>
</div>
Thanks everyone!
WEThanks for the helpful link!
I found the solution to the problem it was very simple and I feel a little stupid asking the question in the first place but, that's how learning works.
We sometimes stumble upon knowledge.
The problem is I was adding the second string outside of the array.
Here is the right way:
array('file' => 'image1',
'caption' => 'Hello!',
'link1' => '<a href="http://www.msnbc.com">Read more</a>',<--Instead of putting the link here
link2' => '<a href="http://www.npr.org">Idea Center</a>'
<-- I was putting the link here out side the array and not properly ending the string.
$i = rand(0, count($images)-1);
$selectedImage = "graphics/{$images[$i]['file']}.png";
$caption = $images[$i]['caption'];
$link1 = $images[$i]['link1'];
$link2 = $images[$i]['link2'];
?>
Output here:
<div id="stage">
<img src="<?php echo $selectedImage; ?>" alt="Random image" />
<p><?php echo $caption; ?></p>
<?php echo $link1; ?>
<?php echo $link2; ?>
</div>
WE -
I am using a
PHP random image
script on a site in which I have 2 different images on each
templated page (random images throgh a site). The two images call
to 2 different folders with the random image script in them (to get
2 distinct images). Thus, 2 different random images. My issue is
that it seems that most browsers at some point do not call for a
new image but use what was there in the last page as it is the same
name:
http://ansano.com/asl/images/random/top/random_image.php
or
http://ansano.com/asl/images/random/bottom/random_image.php
Any idea of how to force a browser to call the PHP script? Or
how to change it so it works site wide?
Thanks!!I've now been sitting looking for this for a while. I don't seem to be able to get it to work.
Do I need to host to a folder first and then to the FTP server after?
I don't seen to be able to find the new page (TEST PAGE) in the folder I used to publish the site to before I went online. Tried searching for it in finder but I don't get any results on (TESTPAGEfiles).
I can see what you are talking bout I only publish to a local folder but I want to publish via the FTP option in iWeb.
Thank you very much for helping me -
Suggestions for simple random image script
Would like to randomly display one of five new JPG banner each time page is loaded.
Your experience would be appreciated.
ThanksSince no one replied, I am posting solution I found.for future inquiries.
Simple PHP Random Image Script
This can be done in one line of text directly in your HTML and a collection of images.
The first step is to gather together the images you wish to have randomly rotated.
Change all of their file names to a numerical order, starting with the number 1.
* 1.jpg
* 2.jpg
* 3.jpg
* 4.jpg
Be sure each image has the same extension (either all jpg, png, or gif),
and that there are no gaps in the numbers.
Also, place these images in their own folder to keep everything organized.
Write the Code
In the HTML of your page, insert the following code where you want an image to display:
<img src="path/<?php echo rand(1,n);?>.jpg" alt="Random Image" />
The “rand” operator will display a randomly generated number between 1 and ‘n’.
Change ‘n’ to the total amount of pictures you have arranged numerically
(or the highest numbered picture you have).
In the example above I only have 4 pictures, therefor I would change it to: rand(1,4); -
Added Captcha Image extension but can't find application in DW CS4
Hi,
I installed DW CS4 about two weeks ago. Yesterday, I installed the PHP Captcha Image extension that I downloaded from www.tecnorama.org for the purpse of using it on my website's Contact Us page (getting lots of SPAM). Per the Extension Manager, the Captcha Image application installed fine but I have no idea where the Application Tab is in CS4 so I can add the Captcha Image to my form. Prior to CS4, I used DW MX and the captcha application after adding it would get applied from the Application Tab /Windows => Behaviour or via the InsertBar but I don't see either in CS4?
Where did my Captcha Image extension go and how do I access it?
Thanks
CarterIgnore the instructions on the tecnorama web page. They don't apply to CS4.
If you're ever in doubt on how to get started with a DW Extension, look for instructions in the Extension Manager in DW CS4 (Commands > Manage Extensions..)
Click on PHP Captcha Image.
Assuming you're already editing a PHP page, the instructions there say: Server Behaviors (Window > Server Behaviors or Ctrl+F9) - > Captcha Image. -
Kaos weaver random image code does not validate with w3c
Hi
I have done a quick test validation on a site I am working
on, I have used Kaos Weaver's Advanced Random Image extension .
When Validating this comes up with about 60 errors, the ones I have
done I have corrected but not uploaded yet. Unfortunately I am not
skilled in java to go about correcting the kaos weaver errors.
Link to w3c:
http://validator.w3.org/check?uri=www.blanc-wall.co.uk%2FUp2Press%2520Website%2Findex.htm
Any help would me much appreciated guys
AndyMick White wrote:
> andy_forbes wrote:
>
>> Hi I have done a quick test validation on a site I
am working on, I
>> have used Kaos Weaver's Advanced Random Image
extension . When
>> Validating this comes up with about 60 errors, the
ones I have done I
>> have corrected but not uploaded yet. Unfortunately I
am not skilled in
>> java to go about correcting the kaos weaver errors.
>>
>> Link to w3c:
>>
http://validator.w3.org/check?uri=www.blanc-wall.co.uk%2FUp2Press%2520Website%2F
>>
>> index.htm
>>
>> Any help would me much appreciated guys
>>
>> Andy
>>
> Bad link
> Mick
Oops, good link, errors are basic, Every image needs an "alt"
attribute,
and "&" needs to be encoded as "&".
Mick -
Extension: Dynamic Images/Advance Random Images
Hi there,
I have downloaded 2 extensions: Dynamic Images or/and
Advanced Random Images (kaosweaver.com); it seems both are the same
and I have used both, works very well when I open the page on
Mozilla Firefox but not on Internet Explorer and strange thing is
when the page is open on IE everything disappears and the only
thing can be seen is the page background!!!
Any suggestion to fix the problem would be appreciated. Thank
you.Babri1,
As always, start by contacting the extension author. I'm sure
that Paul
Davis will help you out.
Randy
> I have downloaded 2 extensions: Dynamic Images or/and
Advanced Random Images
> (kaosweaver.com); it seems both are the same and I have
used both, works very
> well when I open the page on Mozilla Firefox but not on
Internet Explorer and
> strange thing is when the page is open on IE everything
disappears and the only
> thing can be seen is the page background!!!
>
> Any suggestion to fix the problem would be appreciated.
Thank you. -
Using PHP to display semi-random images?
Hello,
I'm looking for help using PHP and MySQL to generate semi-random images on my web site. Here's what I'm trying to do: I have 60 images, but I only want to display 16 at a time (for examlpe http://artisdead.net/antelopegardens.php).
The way I imagine this is, the design has 16 image placeholders. I want Placeholder 1 (the first image) to randomally pull record ID 1, 2, or 3 from the SQL database, while Placeholder 2 pulls record ID 4-6, etc. It's important that one of the first 3 images displays first, while one of the second 3 images displays next, etc.
I've found various ways to randomize all the images, but I'm not understanding how to constrain the randomization the way I'm looking to. Any help would be greatly appreciated. Thanks in advance.Alamo_Melt wrote:
The way I imagine this is, the design has 16 image placeholders. I want Placeholder 1 (the first image) to randomally pull record ID 1, 2, or 3 from the SQL database, while Placeholder 2 pulls record ID 4-6, etc. It's important that one of the first 3 images displays first, while one of the second 3 images displays next, etc.
Before offering a possible solution, I should point out that your plan has a minor flaw. If you display only 16 images, and want the random choice to come from incremental sets of three, the maximum number you can have in your set is 48. The final 12 images will never be selected. For 60 images, you need 20 placeholders. The alternative is to have a total set of 64 images, and make the random choice come from incremental sets of four images.
With that caveat, here's how I would do it. The primary keys of your records might not be consecutive, particularly if records are deleted and new ones added, so it might be a good idea to have a separate column with consecutive numbers from 1 to the the maximum. To select random numbers from incremental groups of three, use the following:
$id = array();
$min = 1;
$max = 3;
for ($i = 0; $i < 16; $i++) {
// generate random number from current set
$id[$i] = mt_rand($min, $max);
// increment the minimum and maximum numbers for the next set
$min += 3;
$max += 3;
// join the selected values as a comma-separated string
$vals = implode(',', $id);
$sql = "SELECT image FROM images WHERE id IN ($vals)";
// excecute the SQL query -
Randomizing image/text on refresh
Hello. I'm new...quite new to DW and web work, but have a small, general understanding of it. I'm an animator and am in the midst of creating my own portfolio site. I don't understand code, at least uber-extreme code. I'm attempting to have specific quotes on my homepage from clients and would like to have them change, or have a new text/quote appear on refresh or upon a new visit to the site (just so it's not the same one everytime).
Would I need to just render out a .swf file in AE or is there a means of doing this within DW w/o using crazy code? Thanks in advance, AndyHTML has no way to do something like this. You would indeed have to use Flash, or JavaScript, or some server-scripting to accomplish that task.
It's quote easy to do with something like PHP, for example, by declaring a random variable in the page, e.g.,
<?php
$imageVar = rand(1,5) /* this will generate a random number between 1 and 5 */
?>
and then using that random variable in the image's source attribute -
<img src="images/random/image<?php echo $imageVar; ?>.jpg" />
If you are getting the idea that you will have to come to grips with code sooner rather than later, then you are on the right track. DW is very punishing to those who won't take the time to learn the underlying technologies....
If you Google "random image" and "Dreamweaver" you may also be able to find extensions that do the same thing for you (in JavaScript). I would recommend that you visit http://www.projectseven.com and search there - I do know that they have such a thing, and can wholeheartedly endorse their products as being the best of show.... -
Alt tags, kaosweaver advanced random images
Hi. In Dreamweaver 8.0
I have installed Advanced Random Images from Kaosweaver: http://www.kaosweaver.com/extensions/details.php?id=5
I would like to do a Sequential Slide Show with 8 images. I would like to add alt tags onto each of these images, but the Kaosweaver will not let me do this with the Sequential Slide Show.
Does anyone know a way/trick to work around this?
Thank you.You would have to direct these questions to Paul Davis, the author of kaosweaver stuff.
However, it sure looks to me as if it does this (snippet taken from the ARI demo on the kaosweaver site) -
// Advanced Random Images End
</script><img src="/assets/images/extdemo/intensa3/neptune_main.gif"
alt="The solid blue is wonderful" title="The solid blue is wonderful" width="300" height="300">
<!-- KW ARI Image -->
</p> -
Random Image not displaying in Live View.
My page is at:
www.andrewjamesartist.co.uk
There's a random image script on the front page.
<img src="randomimages/rotate.php" alt="A Sample Image from the work of Andrew James" />
That's how it is placed in the page.
It shows in preview in browser and it's OK live but it doesn't show in LiveView.
I use a testing server set up with virtual hosts.
MartinMy page is at:
www.andrewjamesartist.co.uk
There's a random image script on the front page.
<img src="randomimages/rotate.php" alt="A Sample Image from the work of Andrew James" />
That's how it is placed in the page.
It shows in preview in browser and it's OK live but it doesn't show in LiveView.
I use a testing server set up with virtual hosts.
Martin -
Need Random Image Script with Links
I am needing a script for random images on my homepage. I
need the image to have its own link depending on what image is
displayed. I would like a php script (non database) if
possibleSee comments on DW forum about random includes and this
particular markup
shown below.
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.dreamweavermx-templates.com
- Template Triage!
http://www.projectseven.com/go
- DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs,
Tutorials & Resources
http://www.macromedia.com/support/search/
- Macromedia (MM) Technotes
==================
"newhorizonhosting.com" <[email protected]>
wrote in message
news:e29on1$buf$[email protected]..
>I figured it out by doing a random include
>
> <?
> srand(time());
> $random = (rand()%3);
> print("$random");
> require_once("./$random.php");
> ?> -
Need Random Image Script with Link
I am needing a script for random images on my homepage. I
need the image to have its own link depending on what image is
displayed. I would like a php script (non database) if
possibleNot sure about the PHP but there are some good scrips on
www.kaosweaver.com
Paul Whitham
Certified Dreamweaver MX2004 Professional
Adobe Community Expert - Dreamweaver
Valleybiz Internet Design
www.valleybiz.net
"newhorizonhosting.com" <[email protected]>
wrote in message
news:e28rpm$8is$[email protected]..
>I am needing a script for random images on my homepage. I
need the image to
>have its own link depending on what image is displayed. I
would like a php
>script (non database) if possible
Maybe you are looking for
-
I have an ancient laptop (from 2005) that has my entire music library. This laptop barely works and some keys don't type anymore. How can I get all this music transferred to another computer, or available to me on the cloud?
-
My Itunes will NOT update!!!! PLEASE HELP!!!!
after i click download now it goes to the next page and says thanks for downloading!!! when really it did nothing! am i doing somthing wrong!?!? HELP PLEASE!
-
I have iTunes 11.1.3. I cannot sync specific songs.
The verision of iTunes I am using will only sync the whole library no matter what songs I have selected. It's not the phone because I just upgraded to the 5s and am still having the same problem. Checked iCloud and no longer show music from iCloud. T
-
Resizing or moving an opacity mask along with the items inside it
I'm trying to resize a opacity mask by doing transMaskItem.resize( 10, //scaleX, 10, //scaleY, true, //[,changePositions] true, //[,changeFillPatterns] true, //[,changeFillGradients] true, //[,changeStrokePattern] 0.1, //[,changeLineWid
-
Hello. After this update(Java for OS X 2013-003) stop working Ps3 media server. How to fix it?