开发者

change two images in php

EDIT: I have to images (or two strings) on a page. One on the left and the other on the right side. I want them to randomly switch their position when refreshing the si开发者_如何转开发te. How can I do this? Thanks.


Try this

$image1 = echo "<img src='image_path'>";
$image2 = echo "<img src='image_path'>";

if(rand(0,1)==0){
   $image3 = $image1;
   $image1 = $image2;
   $image2 = $image3;
 }

<div style="float:right">$image1</div>
<div style="float:left">$image2</div>


Use imagerotate() and rand() functions.


You can use imagerotate for this thing. The documentation has this simple example:

<?php
// File and rotation
$filename = 'test.jpg';
$degrees = 180;

// Content type
header('Content-type: image/jpeg');

// Load
$source = imagecreatefromjpeg($filename);

// Rotate
$rotate = imagerotate($source, $degrees, 0);

// Output
imagejpeg($rotate);

So, just write a script that takes a filename as a parameter (via $_GET) and then rotate it by a random degree (use rand for this). Then just change your image link to rotator.php?file=first.jpg.

Another option is to do the rotation with CSS3 and JavaScript. See this link for more information on rotating with CSS3.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜