Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php中更改两个图像_Php - Fatal编程技术网

在php中更改两个图像

在php中更改两个图像,php,Php,编辑: 我必须在一个页面上添加图像(或两个字符串)。一个在左边,另一个在右边。我希望他们在刷新站点时随机切换位置。我该怎么做?谢谢。使用imagerotate()和rand()函数。您可以使用这些函数。文档中有一个简单的示例: <?php // File and rotation $filename = 'test.jpg'; $degrees = 180; // Content type header('Content-type: image/jpeg'); // Load $sou

编辑: 我必须在一个页面上添加图像(或两个字符串)。一个在左边,另一个在右边。我希望他们在刷新站点时随机切换位置。我该怎么做?谢谢。

使用imagerotate()和rand()函数。

您可以使用这些函数。文档中有一个简单的示例:

<?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);
试试这个

$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>
$image1=echo”“;
$image2=echo“”;
if(rand(0,1)=0){
$image3=$image1;
$image1=$image2;
$image2=$image3;
}
$image1
$image2

为此调用PHP函数。手册页面有一个完整的示例。是的,您可以使用和旋转将文本写入图像that@pekka-抱歉,但先试着理解这个问题。@RIKY有你的问题记录的人说的话有点丰富。无论如何,这个问题最初的措辞是不同的。我想我们都误解了,她指的是“切换位置”,为什么不干脆
rand(0,1)
并降低模数?谢谢。如果在if中有一点输入错误,它应该是:$image3=$image2$image2=$image1$image1=$image3;正如JohnP所说,我使用if(rand(0,1)=0{…}